Largest Amongst Three Numbers

Largest Amongst Three Numbers” is very basic programming Exercise problem. Here, we are given three numbers, entered by user and our task is to write a program to find the largest amongst three number.

Example:

INPUT:
Num1 = 10
Num2 = 20
Num3 = 30
OUTPUT
30 is largest number

As we have only three numbers, we will simply check every number with other two remaining number to find the largest amongst three numbers.

C++ Program to find largest number among three number is as follows:

#include<bits/stdc++.h>  
using namespace std;  
int main()  
{  
    int num1,num2,num3;  
      
    // Scanning the numbers  
    cout<<"Enter the first Number: ";  
    cin>>num1;  
      
    cout<<"Enter the second Number: ";  
    cin>>num2;  
      
    cout<<"Enter the third Number: ";  
    cin>>num3;  
      
    int largest;  
      
    // check if first number is largest  
    if(num1 >= num2 && num1 >= num3)  
    {  
        largest = num1;  
    }  
    // check if second number is largest  
    else if(num2 >= num1 && num2 >= num3)  
    {  
        largest = num2;  
    }  
    // check if third number is largest  
    else if(num3 >= num1 && num3 >= num2)  
    {  
        largest = num3;  
    }  
      
    //Printing the largest number  
    cout<<"The largest number is "<<largest;  
}  

OUTPUT:
Enter the first Number: 10
 Enter the second Number:  20
Enter the third Number: 30
The largest number is 30

Related Posts:

  1. Program to find factorial of a number.
  2. Program to find GCD of two numbers.
  3. Program to find LCM of two numbers.
  4. Program to check whether entered number is odd or even.
  5. Program to check whether entered number is prime number or not.
  6. Program to check whether entered number is palindrome or not.
  7. Program to check whether entered number is Armstrong Number or Not.
  8. Program to convert binary number to octal number.
  9. Program to convert binary number to decimal number.
  10. Program to convert binary number to hexadecimal number.
  11. Program to convert octal number to binary number.
  12. Program to convert octal number to decimal number.
  13. Program to convert octal number to hexadecimal number.
  14. Program to convert decimal number to binary number.
  15. Program to convert decimal number to octal number.
  16. Program to convert decimal number to hexadecimal number.
  17. Program to convert hexadecimal number to binary number.
  18. Program to convert hexadecimal number to octal number.
  19. Program to convert hexadecimal number to decimal number.
  20. Program to check Leap Year.

You may also like...

Leave a Reply

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