求10 个整数中最大值
程序已运行出来(环境是VS2013)
a[]={…………………………};
int num;
num=sizeof(a)/sizeof(a[0]) //求某个未知长度的数组的方法
#include <stdio.h>
#include <windows.h>
int main(){
int i;
int a[10]; //定义一个数组用来存放10个数
int max; //定义一个数max表示最大值
printf("Please enter ten number:");
for (i = 0; i<= 9;i++){
scanf_s("%d",&a[i]);
} //利用循环,给数组中输入数据
max = a[0]; //假设最大值是第一个数,然后利用循环进行比较,若有比原本最大数大的,把这个数再存到max中,最后只要输出max就行
for (i = 1; i < 9;i++){
if (max < a[i]){
max = a[i];
}
}
printf("the max of the ten number is %d",max);
system("pause");
return 0;
}