Dremendo Tag Line

Input 10 numbers and print the largest using for loop in C++

for Loop - Question 8

In this question, we will see how to input 10 numbers and print the largest number among them in C++ programming using for loop. To know more about for loop click on the for loop lesson.

Q8) Write a program in C++ to input 10 numbers and print the largest number among them using for loop.

Program

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

using namespace std;

int main()
{
    int i,n,lar;

    cout<<"Enter 10 numbers\n";
    for(i=1; i<=10; i=i+1)
    {
        cin>>n;
        if(i==1)
        {
            lar=n;		// store the first number
        }
        else if(n>lar)		// compare the previous stored number with the latest entered number
        {
            lar=n;
        }
    }
    cout<<"Largest Number = "<<lar;
    return 0;
}

Output

Enter 10 numbers
15
3
6
9
84
21
34
59
5
12
Largest Number = 84
video-poster