Decision Control

Introduction to Decision Controls

Difference Programming Language has Decision Controls for program execution. The main Decision Controls are

1.If Statement

2.If Else Statement

3.If Else If Statement

4.Switch

C supports two types of decision control statements that can alter the flow of a sequence of instructions. These include conditional type branching and unconditional type branching

Decision Controls

If Statement

If Statement:- The if statement is the simplest form of decision control statements that are frequently used in decision making. The
the general form of a simple if the statement is shown in the below picture.

if statement

/*Emaple for If statement and checking given number is even*/
#include<stdio.h>
void main() {
   int n;
   printf("Enter the number");
   scanf("%d",&n);
   if(n%2==0) {
      printf("given number is even");
   }
}

 

If Else Statement

If Else Statement:- If Statement is true then execute the if block otherwise it is not executed. So, In this case Else Statement is useful for false conditions. Every Else Statement followed by If Statement. 

If else Statement

Example for If Else Statment:-

// The Given number is even or odd
#include<stdio.h>
void main() {
    int n;
    printf("Entete the number");
    scanf("%d",&n);
    if(n%2==0) {
       printf("Given number is even");
    }
    else {
       printf("Given number is odd");
    }
}