C Program to Find Smallest from N Numbers

Question: Write a program in C to read N numbers from users and find the smallest number from them.

Program


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

int main()
{
	 int n, i;
	 float num, sm;
	 clrscr();
	 printf("How many numbers?\n");
	 scanf("%d",&n);
	 printf("Enter number-1: ");
	 scanf("%f", &num);
	 sm = num;
	 i=2;
	 while(i<=n)
	 {
	  printf("Enter number-%d: ",i);
	  scanf("%f", &num);
	  if(num < sm)
	  {
	   sm = num;
	  }
	  i++;
	 }
	 printf("\nSmallest = %0.2f", sm);
	 getch();
	 return(0);
}

Output of the above program :

How many numbers?
4 ↲
Enter number-1: 67 ↲
Enter number-2: 89 ↲
Enter number-3: 99 ↲
Enter number-4: 56 ↲
Smallest = 56.00

Note: ↲ indicates ENTER is pressed.