Selection Control Statements with Examples

Control statements control the flow of the program. These statements execute program statements depending upon a given condition. Control statements help to jump from one part of the program to another part. The control transfer may be conditional or unconditional.

C supports three types of control statements namely selection, repetition and jump statements.

These are also known as branching, decision making, or conditional statements. C supports two selection statements: if and switch. There are different forms of if statements: if only, if-else, if-else-if, and if-else-if ladder.

List of Different control statements in C Programming with their basic function:

  • if, else, switch, case and default are used for selection purposes.
  • do, while and for are used for iterative purposes.
  • goto, break, continue and return are used for jumping purposes.
  • if-else is used to select one out of two possibilities generally.
  • switch is used to select one out of multiple possibilities.
  • while, for and do-while is used to execute a set of statements repeatedly (looping).
  • break is used to come out of a switch/loop.
  • continue takes us to the next iteration of a loop by skipping the remaining statements in the current iteration.
  • return is used to take the control back to the calling function from a function.

Examples on Selection Control Statements in C programming:

Write a Program to check the given number is odd or even using if-else statement.

/* WAP to check the given number is odd or even */
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("Enter any number: ");
scanf("%d",&n);
if(n%2==0)
{
  printf("\n The number is even");
}
else
{
  printf("\n The number is odd");
}
getch();
}

Write a Program to check the given number positive, negative or zero using if > else-if > else statement.

/*WAP to check the given number positive, negative or zero*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("Enter any number: ");
scanf("%d",&n);
if(n>0)
{
printf("\n The number is positive");
}
else if(n<0)
{
printf("\n The number is negative");
}
else
{
printf("\n The number is 0");
}
getch();
}

Write a Program to find the greatest between any three numbers in C programming langugae

/* WAP to find the greatest between any three numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
 int a,b,c;
 printf("Enter any three number: ");
 scanf("%d%d%d",&a,&b,&c);
 if(a>b&&a>c)
 {
  printf("The greater number is %d",a);
 }
 else if(b>c)
 {
   printf("The greater number is %d",b);
 }
 else
 {
   printf("The greater number is %d",c);
 }
  getch();
}

Write a Program to demonstrate Arithmetic Calculations between any two numbers using Switch statement.

/* WAP to demonstrate Arithmetic Calculations between any two numbers */
#include<stdio.h>
#include<conio.h>
void main()
{
int choice;
float a,b;
printf("Enter any two numbers: ");
scanf("%f%f",&a,&b);
printf("Press: \n 1 for multiply \n 2 for Divide \n 3 for addition \n 4 for subtraction \n");
scanf("%d",&choice);
switch(choice)
{
	case 1:
	printf("The result is %f",a*b);
	break;
	case 2:
	printf("The result is %f",a/b);
	break;
	case 3:
	printf("The result is %f",a+b);
	break;
	case 4:
	printf("The result is %f",a-b);
	break;
	default:
	printf("Invalid number! Pls input number between 1-4");
}
getch();
}

Print Friendly, PDF & Email
by Rajesh Bhatt
Rajesh is an IT Lecturer with a keen interest in Technological Research over the world. He is equally passionate about Gadgets, Music & Travelling.

Leave a Comment

Hey, wait!Get Regular Update's

Subscribe Stay Connected, Keep Learning!