Write a program in C++ & Python to find the largest number amongst the numbers entered by the user

By | July 2, 2019

In this program, we will ask the user to enter a list of number and print the highest number amongst them.

C++:

#include<iostream.h>
#include< conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
clrscr();
long int num, max=0, n;
cout<<"How many numbers you want to enter: ";
cin>>n;
for(int i =1; i<=n;i++)
{cout<<"Enter number "<<i<<": ";
cin>>num;
if(max< num)
max= num;
}
cout<<"The maximum number is: "<<max;
getch();
}

Output

How many numbers you want to enter: 3
Enter number 1:23
Enter number 2:23
Enter number 3:533
The maximum number is 533

Python:

n =int(input("How many numbers you want to enter: "))
max=0
for i in range(1,n+1):
    num = int(input("Enter number "+str(i)+":"))
    if max< num:
        max= num
print("The maximum number is",max)

Output:

How many numbers you want to enter: 5

Enter number 1:123
Enter number 2:3434
Enter number 3:235
Enter number 4:234
Enter number 5:1245
The maximum number is 3434

Leave a Reply

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