Professional Documents
Culture Documents
Title of Project: Switch Case Statement
Title of Project: Switch Case Statement
Title of Project: Switch Case Statement
TITLE OF PROJECT
Place: chandwad…………………….
Date: ………………………
1 Ahirrao Bhumika 01
bapu
2 Gholap sweta sanjay 12
3
4
5
6
7
Name of Guide:
INDEX
SR.NO. CONTENT PAGE NO.
1
INTRODUCTION
2 SYNTAX
3 ALGORITH
4 FLOW CHART
5
EXAMPLE
6
PROGRAM
9
INTRODUCTION ( Importance of the Project )
-
syntax
Switch(variable)
Case1;
Statement block;
Break; Case2;
Statement block;
Break;
Case n;
Statement block;
Break
}
Flow chart of switch statement
Example
#include <stdio.h>
int main() {
int num = 8;
switch (num) {
case 7:
printf("Value is 7");
break;
case 8:
printf("Value is 8");
break;
case 9:
printf("Value is 9");
break;
default:
printf("Out of range");
break;
}
return 0;
}
Output:
Value is 8
2)
or Six.
❖ Write a program
calculate area of
rectangle of circle or
triangle by taking
user choice
Algorithm
1. Start
2. Initilize variable
3. Take input for choice from user
4. Take inpute for area from user
5. Case no 1: circle 3.14 * 3.14* r Case no2: rectangle ar = a*b
Case no 3: triangle at = 0.5 * a*b
6. Display output
7. stop
program
# include<stdio.h>
# include< conio.h>
Void main()
{
Clrscr();
Int ac, ar, at, r, a, b, choice;
Printf(“Enter for choice \n”);
Printf(“ A for area of circle \n”);
Printf (“ B for area of rectangle \n”);
Printf (“C for area of triangle \n”);
Scanf (“ % c”, choice);
Switch ( choice )
Case A
Printf (“ Enter radius”);
Scanf (“% d”, r);
Ac= 3.14 * 3.14* r ;
Printf (“ Area of circle is % d “, Ac);
Break;
Case B
Printf ( Enter height & width”,);
Scanf (“%d%d “, & a, & b);
Ar = a*b;
Printf (“ The Area of rectangle is % d”, Ar);
Break;
Case C;
Printf (“ Enter the value of b&h”,);
Scanf (“ % d % d”, &a ,& b);
At = 0.5 * a*b;
Printf (“ triangle is % d”, At); getch
();
}
Aplication of switch statement:-
The switch statement allows us to execute one code block among many alternatives. You can do the
same thing with the if...else..if ladder. However, the syntax of the switch statement is much easier to read
and write.
Advantage of switch