输入20个随机数存入一个数组,然后输出数组中的最大值

2024-12-29 14:05:41
推荐回答(1个)
回答1:

#include "stdio.h"
#include "stdlib.h"
#include "time.h"
int main(void)
{
int i, a[20], max;
srand(time(NULL));
for (i = 0; i < 20; i++)
a[i] = rand() % 100;
max = a[0];
for (i = 0; i < 20; i++)
{
if (a[i] > max)
max = a[i];
printf("%d ", a[i]);
}
printf("\n最大值:% d", max);
return 0;
}