-->





C++ program to find greatest number between three numbers

Program description
This program shows the greatest number between three numbers using if-else-if statement. It takes three numbers as input from user and output the greatest number.

code:



  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int num1,num2,num3;
  6. cout<<" Enter value for first number";
  7. cin>>num1;

  8. cout<<" Enter value for second number";
  9. cin>>num2;

  10. cout<<" Enter value for third number";
  11. cin>>num3;
  12. if(num1>num2&&num1>num3)
  13. {
  14. cout<<" First number is greatest:"<<endl<<"whick is= "<<num1;
  15. }
  16. else if(num2>num1&&num2>num3)
  17. {
  18. cout<<" Second number is greatest"<<endl<<"whick is= "<<num2;
  19. }
  20. else
  21. {
  22. cout<<" Third number is greatest"<<endl<<"whick is= "<<num3;
  23. }
  24. return 0;
  25. }

Note : If you have any query or idea about program 
Comment below.





23 comments:

  1. In this program you never include the #include library so that i am not able to write clrscr(); and getch(); because output screen is not holding after Entering the Third number and also screen is not clear for next time compiling of program.
    using namespace std; is not working!!!!!!!

    ReplyDelete
    Replies
    1. It depends on compiler you are using to write code.
      For Turbo C++ and Borland C++ compiler use the header file
      #inclulde to write clrscr(); and getch()
      They don't work with using namespace std;

      In visual studio
      to clear screen use system("cls")

      Delete
    2. use #include for clrscr and getch

      Delete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. Is this topic connected with your education or is it mostly about your hobbies and free time?

    ReplyDelete
  4. Thanks for the efforts on gathering useful content and sharing here. You can find more questions and answers related to C, C++ programming and all other programming languages Q&A in the below forum.

    C CPP programming and programming languages Q&A

    ReplyDelete
  5. what if two numbers among the three are equal?

    ReplyDelete
  6. This program is a much better version of this with extra functionality.

    #include

    using namespace std;

    int main()
    {
    int num1,num2,num3;

    cout<<"Enter 1st Number : ";
    cin>>num1;
    cout<<"\nEnter 2nd Number : ";
    cin>>num2;
    cout<<"\nEnter 3rd Number : ";
    cin>>num3;

    if(num1>num2 && num1>num3)
    cout<<"\n**** "<num1 && num2>num3)
    cout<<"\n**** "<num2 && num3>num1)
    cout<<"\n**** "<<num3<<" is the largest number. ****";

    if(num1==num2 && num1==num3 && num2==num1 && num2==num3 && num3==num1 && num3==num2)
    cout<<"\n**** All three numbers are same ****";

    else
    cout<<"\n**** Wrong Combination. Try Again ****";




    return 0;
    }

    ReplyDelete
  7. // A Switch Program

    #include
    #include

    using namespace std;

    int main(int argc, char *argv[])
    {

    //Switches (case Structure) //

    int marks;

    cout<<"\t\nEnter the makrs = ";
    cin>>marks;
    cout<<"\t\nCongratulations Your Grade is = ";

    switch (marks)
    {
    case 90:
    cout<<"A\n\n\n";
    break;
    case 80:
    cout<<"B\n\n\n";
    break;
    case 70:
    cout<<"C\n\n";
    break;

    default:
    cout<<"Sorry Try Again Student\n\n";
    break;
    }

    system("PAUSE");
    return 0;
    }

    ReplyDelete
  8. write a program that in put 4 value from the user and find the maximum number using nested if

    ReplyDelete
  9. Its Possible to use double If else in this Program ??

    ReplyDelete
    Replies
    1. Yes You Can. Copy The Code Paste It In Compiler and Do Experiment With Dry Run.

      Delete
  10. why don't u just use array traversing? ain't that simple as shit?

    ReplyDelete
  11. #include
    #include

    void main()
    {
    int x,y,z,max;
    clrscr();
    cout<<"Enter The Three Numbers ";
    cin>>x>>y>>z;

    max=x;
    if (y>max)
    max=y;
    if (z>max)
    max=z;

    cout<<"\n"<<"The Greatest Number among "<<x<<" "<<y<<" "<<z<<" is "<<max;
    getch();
    }

    ReplyDelete
  12. can u please do it with the greatest,the second greatest and the lowest together ,???

    ReplyDelete
  13. how can we write the program for fourth number to find the greatest number in them.

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. #include
    using namespace std;
    int main()
    {
    int num1, num2, num3 , max;
    cin >> num1;
    cin >> num2;
    cin >> num3;
    max = num1;
    if (num2 > max)
    {
    max = num2;
    }
    if (num3 > max)
    {
    max = num3;
    }
    cout << "The greatest number is " << max;
    cin.get();
    cin.ignore();
    return 0;
    }

    ReplyDelete
  16. THANK U SOO MUCH......IT HELPED ALOT......THNX C++

    ReplyDelete
  17. How to find largest number among three using friend function and three classes?

    ReplyDelete
  18. Find largest number among three using friend function and three classes?

    ReplyDelete