Nested if in C++





It is perfectly all right if we write an entire if-else construct within either the body of the if statement or the body of an else statement.

Syntax :

if( boolean_expression 1) {
   // Executes when the boolean expression 1 is true
   if(boolean_expression 2) {
      // Executes when the boolean expression 2 is true
   }
}               

Example:

WAP to check the given natural number is even or odd.
#include<iostream>
using namespace std; 
int main( )
{
 int x ;
 cout<< "Enter any number: ";
 cin>>x;
 if(x>0) {
  if(x%2 == 0)
   cout<< "X is EVEN\n";
  else
   cout<< "X is ODD\n";
 }
 else {
   cout<< "Not Natural Number\n";
 }
 return 0;
}
OUTPUT:
Enter any number: 12
X is EVEN

Next topic is Switch-Case 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


CONTACT DETAILS

info@prowessapps.in
(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017, prowessapps.in, All rights reserved