If else statement

If statement:

In C if else control statement, block of statements are executed when condition is true.  If condition is not true, then else parts block of  statements are executed.

 

 

if else new

 

Example 1

#include <stdio.h>

int main()

{

int p=40,q=20;

if (p == q) {

//if block of statement

printf(” the entered values of p and q as %d and%d are similar”.p,q);

}

else

{

// else block of statement

printf(” the value of p & q as %d and %d aren’t similar” p,q );

}

}

Output

The value of p & q as 40 and 20 aren’t similar

Example 2

#include <stdio.h>

main()

{

int x1 = 1;

if ( x1 == 1 )

printf(“x1 is equal to one.\n”);

else

printf(“In c language For comparing use== (equals oprator) as = is a assignment operator.\n”);

return 0;

}

Output
x1 is equal to one
Write a Program to check whether an integer type by the user is odd or even

#include <stdio.h>

void main()

{

int No;

printf(” Enter one number: “);

scanf(“%d”,&No);

if( No%2 == 0 )

printf(” the enter number %d is an even integer.”,No);

else

//else block of statement

printf(” the specified no. %d is an odd integer no.”,No);

}

Output
Enter one number: 7

The specified no 7 is an odd integer no.

Proram for if else control instructions

 

Leave a Reply

Your email address will not be published. Required fields are marked *