第1个回答 2013-06-15
1.
#include "stdio.h"
#define NUM 10
short fun(short *a,short k);
main()
{
short a[NUM];
short temp;
short k=0;
short count_ji;
for(;;)
{
scanf("%hd",&temp);
if(temp==-1)
break;
a[k++]=temp;
}
count_ji=fun(a,k);
printf("jishu:%hd\noushu:%hd",count_ji,k-count_ji);
}
short fun(short *a,short k)
{
short i;
short count=0;
for(i=0;i<k;++i)
if(a[i]%2)
count++;
return count;
}
2.
#include "stdio.h"
#define N 4
short fun(short *a,short *pmax);
void input(short *a);
main()
{
short a[N];
short max;
short temp;
input(a);
temp=fun(a,&max);
printf("%hd %hd",temp,max);
}
void input(short *a)
{
short i;
for(i=0;i<N;++i)
scanf("%hd",a+i);
}
short fun(short *a,short *pmax)
{
short i;
*pmax=a[0];
for(i=0;i<N;++i)
if(*pmax<a[i])
*pmax=a[i];
for(i=0;i<N;++i)
if(*pmax==a[i])
break;
return i;
}
第2个回答 2013-06-15
#include <stdio.h>
#define N 10
int main()
{
int max=0,i,a[N],k=0;
printf("请为大小为%d的数组赋值!\n",N);
for(i=0;i<N;++i)
scanf("%d",&a[i]);
max=a[0];
for(i=1;i<N;++i)
if(a[i]>max)//如果a[i]大于max就将a[i]的值赋给max。
{
max=a[i];
k=i;//记录下标
}
printf("\n");
printf("该数组最大值是%d下标为%d\n",max,k);
return 0;
}本回答被提问者采纳