void main()
{
int num[10];
int i;
int maxnum;
printf("input 10 numbers: \n");
for (i = 0; i < 10; ++i) {
scanf("%d", &num[i]);
}
printf("they are: ");
for (i = 0; i < 10; ++i) printf("%d ", num[i]);
maxnum = num[0];
for (i = 1; i < 10; ++i) {
if (num[i] > maxnum) maxnum = num[i];
}
printf("\nthe max is %d\n", maxnum);
return 0;
}
或者如下:
#include
int main()
{
float a[10],min,max;
int i;
printf("please enter 10 num\n");
for(i=0;i<10;i++)
{
scanf("%f",&a[i]);
}//输入
min=max=a[0];
//假设第一个数是最小的数,且是最大数
for(i=1;i<10;i++)
{
//依次与其它各数比较
if(a[i]>max)
{
max=a[i];
}
else if(a[i]
min=a[i];
}
}
printf("\nmax is %f min is %f\n",max,min);
}