Pages

Friday, February 13, 2015

C program to find largest and smallest element from a 1D array


C program to find largest and smallest element from a 1D array

#include<stdio.h>
#include<conio.h>

void main()
{
int a[50],i,n,large,small;
clrscr();
printf("How many elements:");
scanf("%d",&n);
printf("Enter the Array:");
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 largest element is %d",large);
printf("
The smallest element is %d",small);

getch();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.