Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views9 pages

Switch Case

Swtich

Uploaded by

fathimackm2019
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)
4 views9 pages

Switch Case

Swtich

Uploaded by

fathimackm2019
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/ 9

//Switch case

//1.write a pgm to enter no: from 1-7 and display the corresponding day of week using
switch case

/*#include <stdio.h>

int main() {

int day;

printf("Enter a number (1 to 7): ");

scanf("%d", &day);

switch(day) {

case 1:

printf("Sunday\n");

break;

case 2:

printf("Monday\n");

break;

case 3:

printf("Tuesday\n");

break;

case 4:

printf("Wednesday\n");

break;

case 5:

printf("Thursday\n");
break;

case 6:

printf("Friday\n");

break;

case 7:

printf("Saturday\n");

break;

default:

printf("Invalid input! Please enter a number between 1 and 7.\n");

return 0;

}*/

//2.Give the output

main( )

char c = 'x' ;

switch ( c )

case 'v' :

printf ( "I am in case v \n" ) ;

break ;

case 'a' :

printf ( "I am in case a \n" ) ;

break ;

case 'x' :
printf ( "I am in case x \n" ) ;

break ;

default :

printf ( "I am in default \n" ) ;

//3.

main( )

int i = 22 ;

switch ( i )

case 121 :

printf ( "I am in case 121 \n" ) ;

break ;

case 7 :

printf ( "I am in case 7 \n" ) ;

break ;

case 22 :

printf ( "I am in case 22 \n" ) ;

break ;

default :

printf ( "I am in default \n" ) ;

}
//5.

main( )

char suite = 3 ;

switch ( suite )

case 1 :

printf ( "\nDiamond" ) ;

case 2 :

printf ( "\nSpade" ) ;

default :

printf ( "\nHeart") ;

printf ( "\nI thought one wears a suite" ) ;

*/

//6.

main( )

int k, j = 2 ;

switch ( k = j + 1 )

case 0 :

printf ( "\nTailor") ;

case 1 :
printf ( "\nTutor") ;

case 2 :

printf ( "\nTramp") ;

default :

printf ( "\nPure Simple Egghead!" ) ;

//7.

main( )

int ch = 'a' + 'b' ;

switch ( ch )

case 'a' :

case 'b' :

printf ( "\nYou entered b" ) ;

case 'A' :

printf ( "\na as in ashar" ) ;

case 'b' + 'a' :

printf ( "\nYou entered a and b" ) ;

//8.

main( )

{
int i = 1 ;

switch ( i - 2 )

case -1 :

printf ( "\nFeeding fish" ) ;

case 0 :

printf ( "\nWeeding grass" ) ;

case 1 :

printf ( "\nmending roof" ) ;

default :

printf ( "\nJust to survive" ) ;

//9.

#include<stdio.h>

void main()

char ch='Y';

switch(ch)

default:

printf("\n YES OR NO");

case 'Y':

printf("YES");

break;

case 'N':

printf("NO");

break;
}

//10.

main()

float num=1.5;

switch(num)

case 1:printf("1");

case 2:printf("2");

default:printf("0");

//11.

main()

int i;

for(i=1;i<=4;i++)

switch(i)

case 1:printf("%d",i);break;

case 2:printf("%d",i);break;

case 3:printf("%d",i);

case 4:printf("%d",i);
}

//soln:12334

//12.

main()

int num=0;

for(num=0;num<2;num++)

switch(num)

case 0: num+=2;

case 1:num+=1;

case 5:num+=2;

default:num+=3;

break;

printf("%d",num);

//soln:8

//13.

main()

{
int num = 4;

switch (num)

default :

printf("\nComputer Science");

case 1 :

printf ("\nUniversity Visvesvaraya College of Engineering");

break;

case 2 :

printf ("\nExperience makes man Exact");

break;

case 3 :

printf ("\nPractice makes man Perfect");

You might also like