if-else statement in c++
If block contains the condition, if condition is true, then the statements of if block will execute and if the condition is false then the statement of else block will execute.
Syntax :
if(boolean_expression) { /* statement(s) will execute if the boolean expression is true */ } else { /* statement(s) will execute if the boolean expression is false */ }
Block Diagram :

Example:
WAP to check no. is +ive or -ive.#include<iostream> int main(){ // local variable declaration: int x; cout<< "Enter any number :"; cin>>x; // check the condition if( x >= 0 ) { /* if condition is true then print the following */ cout<<"Number is Positive"; } else { cout<<"Number is Negative"; } return 0; }OUTPUT 1:
Enter any number: 12 Number is PositiveOUTPUT 2:
Enter any number: -12 Number is Negative
Next topic is if-else-ladder-in-c++
Training For College Campus
We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies
like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.
Please mail your requirement at info@prowessapps.in
Projects For Students
Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.
Students can mail requirement at info@prowessapps.in