C++ Program To Find Greater Number Among Given Three Numbers Full Project For Beginners

  • Post author:
  • Post category:c++
  • Post comments:0 Comments

 

 

main.cpp

 

 

#include<iostream>
using namespace std;
int main()
{
   /* Program By Ghanendra Yadav
   Visit http://www.programmingwithbasics.com/
   */
   double num1, num2, num3;

    cout<<"Enter Three Numbers: \n";
    cin>>num1>>num2>>num3;

   if (num1 > num2 && num1 > num3)
      cout<<"\nGreatest Number Is :"<<num1;

   else if (num2 > num3 && num2 > num1)
      cout<<"\nGreatest Number Is :"<<num2;

   else if (num1 > num1 && num3 > num2)
      cout<<"\nGreatest Number Is :"<<num1;
      
   else if ((num1==num2) && (num2==num3) && (num3==num1))
     cout<<"\nAll Are Equal"; 
   

}

Method 2:-

#include<iostream>
using namespace std;
int main()
{
 /* Program By Ghanendra Yadav
   Visit http://www.programmingwithbasics.com/
   */
    double num1, num2, num3;

    cout<<"Enter Three Numbers: ";
    cin>>num1>>num2>>num3;

    if (num1>=num2)
    {
        if(num1>=num3)
            cout<<num1<<" Is The Largest Number. ";
        else
            cout<<num3<<" Is The Largest Number. ";
    }
    else
    {
        if(num2>=num3)
            cout<<num2<<" Is The Largest Number. ";
        else
            cout<<num3<<" is the largest number.";
    }
    
    return 0;

}

Leave a Reply