C++ program to find largest number of a list of numbers entered through keyboard

C++ program to find largest number of a list of numbers entered through keyboard

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr(); //to clear the screen
int i,n,x,large=0;

cout<<“How many numbers?”;
cin>>n;
for(i=0;i<n;++i)
{
cout<<“nEnter number “<<i+1<<“:”;
cin>>x;
if(x>large)
large=x;
}
cout<<“nnThe largest number is “<<large;
getch();
}

12 thoughts on “C++ program to find largest number of a list of numbers entered through keyboard”

    1. Initially large is 0, as a new number is entered i.e. x, is compared with large, if x is greater then large then large is update. After entering all numbers the final value of large is largest among all numbers.

      I hope it will be clear now.

        1. See there in the for loop the programmer used i<n that is it will run for n-1 (ex if n=3 then the loop will be for n=2) .

  1. Kanchan Agrawal

    Thank you. Will you please write a program using pointer which will take 5 no. and will display the greatest number.

Leave a Comment

Your email address will not be published. Required fields are marked *