c语言中求数组元素的最大值和最小值
1、
#include <stdio.h>
#define NUMBER 5
int main(void)
{
int i;
int a[NUMBER];
puts("please input the score of the students.");
for (i = 0; i < NUMBER; i++)
{
printf("%dst = ", i + 1);
scanf("%d", &a[i]);
}
int max = a[0];
int min = a[0];
for (i = 0; i < NUMBER; i++)
{
if(a[i] > max)
max = a[i];
if(a[i] < min)
min = a[i];
}
printf("max = %d\n", max);
printf("min = %d\n", min);
return 0;
}
2、
#include <stdio.h>
#define NUMBER 8
int main(void)
{
int i;
int a[NUMBER];
puts("please input the score of the students.");
for (i = 0; i < NUMBER; i++)
{
printf("%dst = ", i + 1);
scanf("%d", &a[i]);
}
int max = a[0];
int min = a[0];
for (i = 0; i < NUMBER; i++)
{
if(a[i] > max)
max = a[i];
if(a[i] < min)
min = a[i];
}
printf("max = %d\n", max);
printf("min = %d\n", min);
return 0;
}
版权声明:本文为liujiaxin2018原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。