C program to find the greatest and smallest value among 5 numbers entered by user
//array program to input 5 numbers and to print maximum and minimum value
#include<stdio.h>
#define size 5
int main()
{
int a[size];//array declaration with size 5
int i,max,min;
for(i=0;i<=4;i++)
{
printf(" enter value for location=%d\n",i+1);
scanf("%d",&a[i]);//inputs
}
max=a[0];//assigning first value to max and min
min=a[0];
for(i=0;i<=4;i++)
{
if(max<a[i])//comparing and changing the old value
{
max=a[i];
}
if(min>a[i])//comparing and assigning new value
{
min=a[i];
}
}
printf("the max value=%d and minimum value is %d",max,min);//printing
return 0;
}
No comments:
Post a Comment