C Program to Find Largest from N Numbers

Program


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

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

Output of above program :

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

Note: ↲ indicates ENTER is pressed.