To find the greatest value of 3 numbers, in C + +, code that I use is as follows:
# include <iostream>
using namespace std;
void main () {
int a, b, c, d;
court <<"value of 1:";
cin>> a;
court <<"value 2:";
cin>> b;
court <<"value of 3:";
cin>> d;
c = (a> b? a: b);
court <<"largest value is:" <<(c> d? c: d) <<"\ n";
}
Logic:
Compare the first value second value. Then the larger of these values in comparison with the next value (the value of the three), so that in can be the greatest value among the three variables.
Explanation of code:
As we saw above, the first - first, we create three variables, namely, the variables a, b, c and d. Then, we ask the user to enter values for the variables a, b, and d. After that, we compare the value of each - each variable. C variables are used here as a "tool". C variable itself stores the higher value of
variables a and b. Then displayed the largest value obtained after comparing the variables c and d.
Leave reply