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();
}

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

  1. Sajid

    Unfortunately I don't get the logic behind these statements. Can you please help me out with this code?
    "if(x>large)
    large=x;"

    Reply
    1. Neeraj Mishra

      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.

      Reply
      1. annu

        I didnot get the logic behind cout<<"enter number"<<i+1<<":"; ???? What is the importance of <<i+1<<":" ????

        Reply
        1. S!r DoshHammer

          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) .

          Reply

Leave a Reply

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