C++-if-statement .

In this session i have discussed if statement in C++ .


If statement is a decision making and branching statement in C++ . It is following types .

IF statement .

IF-Else statement .

Else-IF Ladder statement .

Nested IF-Else .


IF-Statement :

If statment is a powerful decision making and branching statment . It is allow to evaluate the specified condition if condition is true then the statement inside the if will be executed other wise control transfer to next statement .

If-statement-syntax :

mvc image

Example : Write a program check the age for voting .

    #include<iostream>
    using namespace std; 
    int main()
    {
         int age=19;
         if(age>17)
         {
              cout<<"Valid for vote";
         }
         cout<<"\nThanks";
         return 0;
    }
    
    OUTPUT : Valid for vote
             Thanks
    


Example : Write a program check the even number .

    #include<iostream>
    using namespace std; 
    int main()
    {
            int x=4;
            if(x%2==0)
            {
                cout<<"Even Number";
            }
            cout<<"\nThanks";
            return 0;
    }
    
    OUTPUT : Even Number
             Thanks
    


Example : Write a program check the odd number .

    #include<iostream>
    using namespace std; 
    int main()
    {
            int x=5;
            if(x%2!=0)
            {
                cout<<"Odd Number";
            }
            return 0;
    }
    
   OUTPUT : Odd Number
   

Welcome to AndroidATPoint.

back image                     next image