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 :

prowessapps.in

Example:

WAP to check no. is +ive or -ive.
#include<stdio.h>
int main(){
// local variable declaration:
  int x;
  printf("Enter any number :");
  scanf("%d",&x);
  // check the  condition
  if( x >= 0 ) {
/* if condition is true then print 
   the following */

    printf("Number is Positive");
   }
   else
   {
     printf("Number is Negative");
   }
  return 0;
}                    
                
OUTPUT 1:
Enter any number: 12
Number is Positive
OUTPUT 2:
Enter any number: -12
Number is Negative

Next topic is if-else ladder statement






 



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-9026070669 , +91-9451396824

© 2016, prowessapps.in, All rights reserved