运行结果:
C语言代码:
/* c how to program 习题3.23 */
#include <stdio.h>
#include <stdlib.h>
int main()
{
//分别定义变量
int counter = 0;
int number = 0, largest=0;
//当counter++少于10,进入循环
while(counter++ < 10){
//获取一个非负数,赋值给number
printf("请输入第%d个非负数:", counter);
scanf("%d", &number);
//比较大小,并把最大数赋值给largest
if( number > largest){
largest = number;
}
}
//打印最大数
printf("\n最大的数值是:%d\n", largest);
return 0;
}