Program for accepting values in an array and finding greatest and smallest value in that array.
Program for accepting values in an array and finding greatest and smallest value in that array.
/*Program for finding greatest and smallest value in an array.*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,g,s;
clrscr();
printf("\nEnter 5 values in array: \n");
for(i=0;i<=4;i++)
{
scanf("\n%d",&a[i]);
}
g=s=a[0];
printf("\n Accepted array values are:");
for(i=0;i<=4;i++)
{
if(g<a[i])
g=a[i];
if(s>a[i])
s=a[i];
printf("%d\t",a[i]);
}
printf("\n Greatest value is=%d",g);
printf("\n\n Smallest value is=%d",s);
getch();
}
Comments
Post a Comment