C Program to Input N Numbers and Find Greatest and Smallest

0
13
digitalample eye
Write a C program to input ‘n’ numbers and find out greatest and smallest number.

C Program to Input N Numbers and Find Greatest and Smallest Number.
Source Code, 

#include <stdio.h>
#include <conio.h>
void main()
{
int i,n,num[100],largest,smallest;
clrscr();
printf("Enter the value of n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter any number");
scanf("%d",&num[i]);
}
largest=num[0];
smallest=num[0];
for(i=0;i<n;i++)
{
if(largest<num[i])
largest=num[i];
if(smallest>num[i])
smallest=num[i];
}
printf("Largest number=%d",largest);
printf("nSmallest number=%d",smallest);
getch();
}

LEAVE A REPLY

Please enter your comment!
Please enter your name here