0% found this document useful (0 votes)
30 views11 pages

C Switch Case Guide for Students

Uploaded by

dhdbbd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views11 pages

C Switch Case Guide for Students

Uploaded by

dhdbbd
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Presentation on

Switch Case in C Programming

By
Sabrina Faisal
B.Tech CS (2024-28)
2024105757
SRMS CET, Bareilly
Contents

• Introduction
• Syntax
• Example Program 1
• Example Program 2
• Bibliography
Introduction

• It is a decision-making statement in C.
• It allows a variable to be tested for
equality against a list of values.
• Each value is called a case.
• The variable being switched on is checked
for each switch case.
Syntax
switch(x) {

case 1:
statement; // if expression equals Value1
break; //optional
case 2:
statement; // if expression equals Value2
break;
……

default: //optional
Statement; // if expression is other than the specific values above
}
C program to check if the addition of two numbers results in
either a total of 5 or 4.

#include <stdio.h>
#include <conio.h>
int main() {

int num1 = 1;
int num2 = 3;

switch(num1 + num2){
case 5:
printf("The addition of %d and %d results in 5\n", num1, num2);
break;

case 4:
printf("The addition of %d and %d results in 4\n", num1, num2);
break;

default:
printf("The addition of %d and %d does not result in either 4 or 5\n", num1,
num2);
}
getch();
return 0;
}
Grade Checking C Program using Switch Statement

#include <stdio.h>
#include <conio.h>

int main(){

char grade;
printf("Enter your grade: ");
scanf("%c",&grade);

switch(grade){
case 'A' :
printf("Outstanding!\n" );
break;
case 'B':
printf("Excellent!\n");
break;
case 'C':
printf("Well Done\n" );
break;
case 'D':
printf("You passed\n" );
break;
case 'F':
printf("Better try again\n" );
break;
default :
printf("Invalid grade\n" );
}

printf("Your grade is %c\n", grade);

getch();
return 0;
}
Bibliography

https://www.geeksforgeeks.org/c-switch-statement/

https://www.codecademy.com/resources/docs/c/switch

https://www.tutorialspoint.com/cprogramming/switch_sta
tement_in_c.htm
Thank You

You might also like