C语言高手进来帮个忙

2024-12-21 20:57:55
推荐回答(3个)
回答1:

题1:
#include
int fun(int *a,int n,int *odd,int *even)
{
int i,Sodd=0,Seven=0;
for(i=0;i {
if(a[i]%2==0) Sodd=Sodd+a[i];
else Seven=Seven+a[i];
}
*odd=Sodd;
*even=Seven;
return 0;
}
int main()
{
int i,n,a[100];
int odd=0,even=0;
puts("Please input n:\n");
scanf("%d",&n);
puts("Please input arrow element:\n");
for(i=0;i {
scanf("%d",&a[i]);
}
fun(a,n,&odd,&even);
printf("The sum of odd is %d.\nThe sum of even is %d.\n",odd,even);
}

题2:
#include
int *match(int n,int *a)
{
int i,tap=0;
for(i=0;tap==1||i<10;i++)
{
if(a[i]==n)
{
tap=1;
a[i]=0;
break;
}
}
if(tap==0) return &a[10];
else return 0;
}
int main()
{
int i,n,a[11],*sp;
printf("Please input arrow element:\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
puts("Please input element you want to serch:\n");
scanf("%d",&n);
puts("The element you inout is:\n");
for(i=0;i<10;i++)
printf("%d ",a[i]);
printf("\n");
sp=match(n,a);
printf("a[10]'s adress is %d.\n",sp);
for(i=0;i<10;i++)
printf("%d ",a[i]);
printf("\n");
}

回答2:

fun(int *a, int n, int *odd, int *even)
{
int i;
*odd=0;
*even=0;
for(i=0;i{
if(*(a+i)%2)
*odd+=*(a+i);
else
*even+=*(a+i);
}
}

int *match(int *a, int value,int n)
{
int i;
int *readd=a+n-1;

for(i=0;i{
if(*(a+i)==value)
{
*(a+i)=0;
readd=a+i;
}
}
return readd;
}

回答3:

void fun(int *a,int n,int *odd,int *even)
{
int i;
for (int i=0;i {
if ( (*a)% 2 == 0)(*dd)++;else (*even)++
}
}
int *match(int *a,int n,int f)
{
int i;
for (int i=0;i {
if (*a==f)
{
*a=0;
return a;
}
}
return a;
}