/* C Program To Find The Largest And Smallest Numbers In A Given Set Of Numbers */
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main()
{
int n,i,large,small,a[20];
printf("Enter a number of elements:\n");
scanf("%d", &n);
if(n>0)
{
printf("Enter the elements one by one:\n");
for(i=0;i<n;i++)
{
scanf("%d", &a[i]);
}
i=0;
large=a[i];
small=a[i];
for(i=0;i<n;i++)
{
if(a[i]>large)
{
large=a[i];
}
else if(a[i]<small)
{
small=a[i];
}
}
printf("Largest number: %d\n",large);
printf("Smallest number: %d\n",small);
}
return 0;
}
No comments:
Post a Comment