IF statement

IF statement:

In “if” control statement, perticular block of code is executed when a given condition is true.

if

 

Example 1

#include <stdio.h>

int main()

{

int l=40,m=40

; if (l == m)

{

Printf(“Values of l and m are equal”);

}

}

Output

Values of l and m are equal

Example 2

#include <stdio.h>

int main()

{

int p1;

printf(“Enter value of an integer: “);

scanf(“%d”, &p1);

if (p1 < 0)

{

printf(“You entered %d.\n”, p1);

}

printf(“The if statements are very easy.”);

}

output

Enter value of an integer: -4

You entered -4.

The if statements are very easy.

Write a Program to check whether an integer type by the user is odd or even
#include &lt;stdio.h&gt;

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 *