If Else Statement In C++


if We want to perform both true & false statement then if-else statement is best for us.


Syntax of if-else statement

if(condition){

True statement;

}else{

False statement;

}


Simple Example Of If Else Statement In C++

Check a Number is positive and Negative


#include <iostream>

using namespace std;

int main(){

int x;

cout<<“Enter a Number:”;

cin>>x;

if(x>0){

cout<<“Number is Positive: <

}else{

cout<<“Number is Negative:”<

}

return 0;

}


Output:
Enter a Number : 3 Number is Positive

Enter a Number -9 Number is negative