Display Largest number among n input Numbers in C

Display the largest number out of n input numbers in C.

This is today’s program. Input n different integer numbers and check one by one which one is biggest. In last, display the largest one.

Display the largest number out of n input numbers in C

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

void main()
{
int n, i=0,big;
char choice;
clrscr();
choice='y';
n=0;
big=n;
do
{
printf("Enter any number to check for largest:");
scanf("%d",&n);
i++;
if(n>big)
{
big=n;
}

printf("Do you want to check more numbers, y=yes and n=no:");
scanf("%c",&choice);

while(choice!='n');

printf("Big number from %d input numbers=%d",i,big);
getch();
}

Output

Enter any number to check for largest: 5

Do you want to check more numbers, y=yes and n=no: y

Enter any number to check for largest: 50


Do you want to check more numbers, y=yes and n=no: y
 
Enter any number to check for largest: 8

 
Do you want to check more numbers, y=yes and n=no: n

Big number from 3 input numbers=50

Program Code Execution (PCE)

Above I complete the largest number out of n input numbers program in C. As you also checked, it is a very easy to program. You just need to know the loops and conditional statements.

First, assign some integer variables (n, i, big) and one character variable (choice).

I am using do-while loop but you can use any one loop to solve this code.

Until user input ‘n’ in choice variable our do-while loop will be executed and it asks the user to input a number.

When the loop terminates, a ‘big’ variable holds the biggest number value. You just print the value of ‘big’ variable.

Hope that you understand a program to find the largest number in C.

Other programs

Please ask you questions in below comment section. If you love technology, you can visit my another blog https://zerootech.com

Leave a Comment

error: Don\'t make piracy - Write your own content :)