Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

C Program to Find Largest and Smallest Number among N

// C program to find the smallest and largest element in an array

#include<stdio.h>

int main()
{
int a[50],i,n,large,small;
printf(“
Enter the number of elements : “);
scanf(“%d”,&n);
printf(“
Input the array elements : “);
for(i=0;i<n;++i)
scanf(“%d”,&a[i]);

large=small=a[0];

for(i=1;i<n;++i)
{
if(a[i]>large)
large=a[i];

if(a[i]<small)
small=a[i];
}

printf(“
The smallest element is %d
”,small);
printf(“
The largest element is %d
”,large);

return 0;
}
 
PREVIOUS NEXT
Tagged: #C #Program #Find #Largest #Smallest #Number #N
ADD COMMENT
Topic
Name
6+1 =