Table of Contents
Introduction
This program of C++ programming will find the largest number among the three numbers entered by the user.
Here we will use the if-else statement.
Moreover, to understand this program, you should know about
1. Operators
2. if-else statement
Program
#include<iostream> using namespace std; int main() { float x,y,z; cout<<"Enter three values\n"; cin>>x>>y>>z; if( (x>=y)&&(x>=z)) cout<<x<<" is greatest among all."<<endl; else if( (y>=x)&&(y>=z)) cout<<y<<" is greatest among all."<<endl; else cout<<z<<" is greatest among all."<<endl; return 0; }
Output
Explanation
The program asks the user to enter three values, and that values get stored in ‘x’, ‘y’, and ‘z’.
The values entered by the user are x=25, y=25, and z=10.
if( (x>=y)&&(x>=z))
The above if statement gives a true result i.e., 25>=25 && 25>=10
Thus, 25 is the greatest among all.
If in case it gives a false result, then the control moves to the else if statement and work accordingly.
0 Comments