Computer Science, asked by ashayjoshi81, 6 hours ago

WAP in C++ to find maximum number between two numbers.​

Answers

Answered by anindyaadhikari13
1

\texttt{\textsf{\large{\underline{Solution}:}}}

The given co‎de 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;

}

\texttt{\textsf{\large{\underline{Explanation}:}}}

  • 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