Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

The if Selection Statement in C

August 9, 2013 Posted by: GPA Views: 668 0 comments

Selection if structure helps to choose alternate statement.The structure of an if statement is as follows:

if ( expression )
    statement1
else 
    statement2

The pseudocode statement

if age is greater than or equal to 50 then

    show true

end if  

If the condition age is greater than or equal to 50” is true, then print "true". If the condition is false, the printing is ignored. The C compiler ignores white-space characters like blanks, tabs and newlines used for indentation and vertical spacing.

The preceding pseudocode If statement may be written in C as

if ( age >= 60 ) {
     printf( "true" );

The if…else Selection Statement 

The if selection statement show action only when the condition is true, otherwise the action is skipped. The if…else selection statement allows you to specify that different actions are to be performed when the condition is true than when the condition is false. For example, the pseudocode statement 

if age is greater than or equal to 50 then

    show true 

else

     show false  

end if 

The preceding pseudocode if…else Selection may be written in C as

if ( age >= 60 ) {
     printf( "Name" );
else{

     printf( "No such name" );

}

Example:

 

  
  
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]){
   int age=50;
   if(age>=50){
      printf("true");
   }else{
      printf("false");
   }
   system("PAUSE");
   return 0;
}

Output

true

0 Comments...

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe