Control Statements in C programming language

The order in which the statements are executed are called control flow. The statements that are used to control the flow of execution of program are called control statements. C Language supports following control statements.

1. If Statement
        Branching is the process of choosing the right branch for execution, depending on the result of “conditional statement”.
ex: Write a Program to find biggest among two numbers
#include <stdio.h>
int main()
{
int a, b;
printf( “ enter two numbers:”);
scanf(“%d%d”,&a,&b);
if (a>b) printf(“ a is the biggest number”);
if (b>a) printf(“ b is the biggest number”);
if (a==b) printf (“ a and b are equal”);
}

2. If –else statement
         Unlike “if statement” where you could only specify code for when condition is true; for “if else statement” you can also specify code for when the condition is not True (false).
ex: Program to find biggest among two numbers using (if-else)
#include <stdio.h>
int main()
{ int a, b;
printf( “ enter two numbers:”);
scanf(“%d%d”,&a,&b);
if (a>b) printf(“ a is the biggest number”);
else printf(“ b is the biggest number”);
}

3. Nested- if statement
             Using “if…else statement” within another “if…else statement” is called ‘nested if statement’. “Nested if statements” is mainly used to test multiple conditions The if-else constructs can be nested (placed one within another) to any depth. General forms: if-if-else and if-else-if.
ex: Program to find biggest among two numbers using nested-if statement:
#include <stdio.h>
int main()
{ int a, b;
printf( “ enter two numbers:”);
scanf(“%d%d”,&a,&b);
if (a>b) printf(“ a is the biggest number”);
else if (b>a) printf(“ b is the biggest number”);
else printf(“ a and b are equal”);
}

learn more
Switch statements in C programming language
Previous
Next Post »