-->

WAP to understand conditional operator.

//program to understand conditional/ternary operator
#include <iostream>//header file
#include<stdlib.h>
using namespace std;//to handle all standard characters/functions,reserved words  used in program. we do not use in turboc++ compiler
int main()//main function
{
    int number1,number2;
    cout<<"enter two numbers"<<endl;//prints message to input numbers
    cin>>number1>>number2;          //gets inputs using chaining concept
    system("cls");                  //clears the screen
    cout<<"number1="<<number1<<endl<<"number2="<<number2<<endl;
    number1>number2?cout<<"number1="<<number1<<" is greater than"<<"number2="<<number2<<endl:
    cout<<"number1="<<number1<<" is smaller than"<<"number2="<<number2<<endl;
    //this part tests the condition. If the first part is true then first cout is printed. If not second part is printed.
    return 0;
}

No comments:

Post a Comment