WAP in C to Find Smallest Element in an Array?

#include<stdio.h>
#include<conio.h>
int main()
{
int a[30],i,num,smallest;
clrscr();
printf(“\nEnter size of array:”);
scanf(“%d”, &num);
printf(“\nEnter the elements of array:”);
//Read n elements in an array
for (i = 0; i < num; i++)
scanf(“%d”, &a[i]);
//Consider first element as smallest
smallest = a[0];
for (i = 0; i < num; i++)
{
if (a[i] < smallest)
{
smallest = a[i];
}
}
// Print out the Result
printf(“\nSmallest Element : %d”, smallest);
getch();
return(0);
}

Output :-

smallarr

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s