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:
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:
- #include<iostream>
- using namespace std;
- int main()
- {
- int num1,num2,num3;
- cout<<" Enter value for first number";
- cin>>num1;
- cout<<" Enter value for second number";
- cin>>num2;
- cout<<" Enter value for third number";
- cin>>num3;
- if(num1>num2&&num1>num3)
- {
- cout<<" First number is greatest:"<<endl<<"whick is= "<<num1;
- }
- else if(num2>num1&&num2>num3)
- {
- cout<<" Second number is greatest"<<endl<<"whick is= "<<num2;
- }
- else
- {
- cout<<" Third number is greatest"<<endl<<"whick is= "<<num3;
- }
- return 0;
- }
Note : If you have any query or idea about program
Comment below.
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.
ReplyDeleteusing namespace std; is not working!!!!!!!
It depends on compiler you are using to write code.
DeleteFor 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")
use #include for clrscr and getch
DeleteThis comment has been removed by a blog administrator.
ReplyDeleteIs this topic connected with your education or is it mostly about your hobbies and free time?
ReplyDeleteIt concerns with my education.
DeleteThanks 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.
ReplyDeleteC CPP programming and programming languages Q&A
what if two numbers among the three are equal?
ReplyDeleteThis program is a much better version of this with extra functionality.
ReplyDelete#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;
}
Yes Hassan Malik. Your Solution Is Also Write.
Delete// A Switch Program
ReplyDelete#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;
}
write a program that in put 4 value from the user and find the maximum number using nested if
ReplyDeleteIts Possible to use double If else in this Program ??
ReplyDeleteYes You Can. Copy The Code Paste It In Compiler and Do Experiment With Dry Run.
Deletewhy don't u just use array traversing? ain't that simple as shit?
ReplyDelete#include
ReplyDelete#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();
}
can u please do it with the greatest,the second greatest and the lowest together ,???
ReplyDeletehow can we write the program for fourth number to find the greatest number in them.
ReplyDeleteThis comment has been removed by the author.
ReplyDelete#include
ReplyDeleteusing 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;
}
THANK U SOO MUCH......IT HELPED ALOT......THNX C++
ReplyDeleteHow to find largest number among three using friend function and three classes?
ReplyDeleteFind largest number among three using friend function and three classes?
ReplyDelete