Our website is made possible by displaying online advertisements to our visitors.Please consider supporting us by disabling your ad blocker.
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Translate it in your own Language

Print this Job Post

Print Friendly and PDF

Thursday, May 1, 2014

The decision control structure

  • In decision control statements (C if else and nested if), group of statements are executed when condition is true.  If condition is false, then else part statements are executed.
There are 3 types of decision making control statements in C language. They are,
  1. If statement
  2. If-else statement
  3. Nested if statement
 NOTE- PLEASE FIND THE ATTACHMENT WITH THIS NOTES FOR SYNTAX AND DESCRIPTION OF DECISION CONTROL STATEMENT


 Example program for if statement in C:
      
In “if” control statement, respective block of code is executed when condition is true.

#include<stdio.h>
#include<conio.h>
void main()
{
  int m=40,n=40;
  if (m == n)
  {
      printf("m and n are equal");
  }
getch();
 }

Output:
m and n are equal

Example program for if else statement in C:
      
In C if else control statement, group of statements are executed when condition is true.  If condition is false, then else part statements are executed.

#include <stdio.h>
#include<conio.h>
void main()
{
  int m=40,n=20;
  if (m == n) {
      printf("m and n are equal");
  }
  else {
        printf("m and n are not equal");
  }
 getch();
 }                                               

Output:
m and n are not equal


Example program for nested if statement in C: 
  •  In “nested if” control statement, if condition 1 is false, then condition 2 is checked and statements are executed if it is true. 
  • If condition 2 also gets failure, then else part is executed.

#include <stdio.h>
#include<conio.h>
void main()
{
int m=40,n=20;
if (m>n)
{
printf("m is greater than n");
}
else if(m<n>

printf("m is less than n");
}
else

printf("m is equal to n");
}
getch();
}

Output:
m is greater than n


No comments:

Post a Comment

Copyright @ CrackMNC 2014-2024
Divas Nikhra Theme by Crack MNC