Conditional operator




Consider the second solution to the problem of finding the maximum of two numbers.
In the second program, we will first write the maximum value to an additional variable (give it the name Max)

Task
1. Run the program
2. Analyze the result and make sure that the variable Max gets the value of the variable A if A> B and Max = B if B> A
3. Answer the question: What block will be executed if A = B?
C++
1
#include <iostream>    
2
using namespace std;  	    
3
main()        
4
{    	    
5
float A, B, Max;    	    
6
cin>>A>>B;  	    
7
if ( A > B ) // заголовок - проверка условия    
8
{    	    
9
  Max = A; // если условие истинно, то выполняется блок операторов, стоящий после слова "if" (если)    
10
}    	    
11
else    	    
12
{    	    
13
  Max = B; // если условие ложно, то выполняется блок "else"  (иначе)    
14
}        
15
cout<<"Maximum "<<Max;    	    
16
}       
Your last submission is saved in the editor window.
     

Results:

All results: