求十个整数中的最大整数

1.用户从键盘输入十个整数,将这十个整数存入一个一维数组中。
2.令数组中的第一个元素为max,利用循环,将数组中所有整数遍历,一一比较,找到最大值。

#include <stdio.h>
#include <windows.h>

int main()
{
    int max=0;
    int i;
    int a[10]={0};
    printf("Enter 10 numbers:");
    for(i=0;i<=9;i++){     //将用户输入的数字依次读进数组中
        scanf("%d",&a[i]);}
    max=a[0];
    for(i=0;i<=9;i++){
        if(a[i]>max){     //遍历数组,若a[i]大于max,则更新max的值
        max=a[i];}
    }
    printf("max:%d",max);
    system("pause");
    return 0;

}

猜你喜欢

转载自blog.csdn.net/qq_43632625/article/details/89460748