WAP in C++ to find maximum number between two numbers.
Answers
Answered by
1
The given code is written in C++.
#include <iostream>
using namespace std;
int main() {
int a,b,max;
cout<<"Enter first number: ";
cin>>a;
cout<<"Enter second number: ";
cin>>b;
max=(a>b)?a:b;
cout<<"The maximum of the two numbers is: "<<max;
return 0;
}
- The problem is solved using ternary operators.
- If the first number is greater than the second number, then the first number is stored in max variable. If the first number is less than the second number, then the second number is stored in max variable.
- Now, the 'max' variable is displayed on the screen.
See the attachment for output.
Attachments:
Similar questions