WAP to find largest and smallest number in an array ?
#include<stdio.h>
int main()
{
int array[50],size,i,b,s;
printf("Enter the size of the array: ");
scanf("%d",&size);
printf("Enter %d elements in to the array: ", size);
for(i=0;i<size;i++)
scanf("%d",&array[i]);
b=array[0];
for(i=1;i<size;i++)
{
if(b<array[i])
b=array[i];
}
printf("Largest element: %d",b);
s=array[0];
for(i=1;i<size;i++)
{
if(s>array[i])
s=array[i];
}
printf("Smallest element: %d",s);
return 0;
}
Sample Output:
Enter the size of the array: 4
Enter 4 elements in to the array: 2 7 8 1
Largest element: 8
Smallest element: 1
No comments:
Post a Comment