Friday, 16 December 2016

C++ Program To Find Greater Number. Among Given Three Number

Problem :- Write a C Program for find a greatest number among given three number .ex-you have to given three number ,number may be Integer, Float, Double You Task is to find a Greatest number Input given by User

Logic :- To solve this problem we need to compare all three numbers each other .for better explanation we need three number assume that numbers are 17 ,45 ,56

Step 1 :- First We Compare 17 to 45 and 56 if it is greatest then we can say that 17 is greatest else we go to next step

Step 2:- Then we compare 45 to 56 and 17  if it is greatest then we can say that 45 is greatest else we go to next step

Step 3:- Then we compare 56 to 45 and 17  if it is greatest then we can say that 56 is greatest else we go to next step (Special Case)


Step 4:- This is the last case if all numbers are same or equal then it will print a message that 
" All INPUT ARE EQUAL "


See Also :- C Program To Find Greater Number. Among Given Three Number

Solution :-

Method 1:-

#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;

}

See Also :- Java Program To Find Greater Number. Among Given Three Number

Output :-


C++ Program To Find Greater Number. Among Given Three Number


C++ Program To Find Greater Number. Among Given Three Number

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment