Q:

write c++ program to read two inputs and find the maximum by using switch statement only

0

write c++ program to read two inputs and find the maximum by using switch statement only

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;
int main()
{
    int num1, num2;

    /* Input two numbers from user */
    cout<<"Enter first number";
    cin>>num1;
    cout<<"Enter second number";
    cin>>num2;

    /* Expression (num1 > num2) will return either 0 or 1 */
    switch(num1 > num2)
    {   
        /* If condition (num1>num2) is false */
        case 0: 
            cout<<num2<<" is maximum";
            break;
        /* If condition (num1>num2) is true */
        case 1: 
            cout<<num1<<" is maximum";
            break;
    }
    return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now