There are many ways to identify largest or smallest number from user input. Here we are using for loop.
// Program to find smallest and largest number from user input.
#include<stdio.h>
void main()
{
int large,small,no,range,i;
printf ("\n\tFrom how many numbers you want to identify smallest and largest\t");
scanf ("%d", &range);
printf ("\n\tEnter number 1==>");
scanf ("%d", &no);
large = no;
small=no;
for (i=1; i<= range -1 ; i++)
{
printf ("\n\t Enter number %d ==> ",i+1);
scanf ("%d",&no);
if (no >= large)
large = no;
if (no <= small)
small = no;
}//end of For loop
printf ("\n\t The largest number is %d", large);
printf ("\n\t The smallest number is %d", small);
}
Output
From how many numbers you want to identify smallest and largest 6
Enter number 1==>11
Enter number 2 ==> 11
Enter number 3 ==> 22
Enter number 4 ==> 22
Enter number 5 ==> 33
Enter number 6 ==> 44
The largest number is 44
The smallest number is 11
We can write this program using various loop and logic.