In: Computer Science
Write a C program that selects and displays the maximum value of five numbers to be entered when the program is executed. (Hint : Use a for loop with both a scan_s and if statement inside the loop.)
#include<stdio.h>
int main()
{
int i,MAX;
int a[5];
for(i=0;i<5;i++)
{
scanf("%d",a[i]);/* input 5 numbers
*/
}
MAX=a[0];/*initialize the first number as maximum
value*/
for(i=0;i<5;i++)
{
if(a[i]>MAX)
{
MAX=a[i];
}
}
printf("the maximum of 5 numbers is%d",MAX);
return 0;
}