Write a C++ statement using Conditional Operator to display maximum
among three numbers a, b, c.
Answers
Answered by
5
Answer:
ABC plz like and follow me and mark as brainlist plz
Answered by
2
C++ program using Conditional Operator find maximum number among three numbers
Program:
#include<iostream> //including header file for use basic function
using namespace std; //using namespace
int main() //defining main method
{
int a,b,c,largest_number; //defining variables
cout<<"Enter any there numbers:"; //message
cin>>a>>b>>c; //input numbers
largest_number=(a>b&&a>c?a:b>c?b:c); //check condition using Conditional operator
cout<<"largest_number is:"<<largest_number; //print value
return 0;
}
Output:
Enter any there numbers:22
23
12
largest_number is:23
Explanation:
- In the above C++ program, firstly header file is included, then the main method is defined.
- Inside the main method, four integer variable is declared, that are a, b,c, and largest_number.
- The a, b, and c variable is used to take input by the user and the fourth variable that is largest_number is used to holds the largest value among them.
- To check the largest value we use a conditional operator that is also known as Ternary Operator that checks the largest value and uses the largest_number variable for hold value.
- In the last, the cout function is used to print the largest value.
Learn more:
- Conditional Operator: https://brainly.in/question/5506721
- Largest number in three numbers: https://brainly.in/question/4758314
Similar questions
English,
6 months ago
Math,
6 months ago
Math,
6 months ago
English,
1 year ago
Environmental Sciences,
1 year ago