0% found this document useful (0 votes)
5 views2 pages

C program Lab Material for practice on switch-case

The document provides examples of switch case statements in C programming, demonstrating how to handle user input for both integers and characters. It includes a nested switch case example to illustrate handling multiple conditions. Each example is accompanied by code snippets that show the structure and functionality of switch statements.
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)
5 views2 pages

C program Lab Material for practice on switch-case

The document provides examples of switch case statements in C programming, demonstrating how to handle user input for both integers and characters. It includes a nested switch case example to illustrate handling multiple conditions. Each example is accompanied by code snippets that show the structure and functionality of switch statements.
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/ 2

Computer Programming Lab

switch case statements:

#include<stdio.h> #include<stdio.h>
int main() int main()
{ {
int choice; int choice;
printf("Enter a number:"); printf("Enter a number:");
scanf("%d",&choice); scanf("%d",&choice);

switch(choice) switch(choice)
{ {
case 1: case 1:
printf("You typed 1"); case 2:
break; printf("You typed 1 or 2");
case 2: break;
printf("You typed 2"); case 3:
break; case 4:
case 3: printf("You typed 3 or 4");
printf("You typed 3"); break;
break; default:
default: printf("You typed something else");
printf("You typed something else"); }
} return 0;
return 0;
}
}

#include<stdio.h>
int main()
{
char choice;
printf("Enter a character:");
scanf("%c",&choice);

switch(choice)
{
case 'a':
printf("You typed a");
break;
case 'b':
printf("You typed b");
break;
default:
printf("You typed something else");
}
return 0;

}
Nested switch case statement:

#include <stdio.h>
int main ()
{
int a,b;
printf("Enter the value of a and b:");
scanf("%d %d",&a, &b);

switch(a)
{
case 1:
printf("This is part of outer switch\n", a );
switch(b)
{
case 2:
printf("This is part of inner switch\n", a );
break;
default:
printf("Inner switch default value\n");
}
break;
default:
printf("Default value\n");
}
return 0;
}

You might also like