How to make a progarm using switch case statement?

Showing Answers 1 - 4 of 4 Answers

karthik

  • Sep 15th, 2006
 

#include<stdio.h>

main()

{

int  n;

printf("Enter 1 or 2");

scanf("%d",&n);

switch(n)

{

case 1:

{

printf("hai");

break;

}

case 2:

{

printf("hello");

break;

}

default:

{

printf("enter 1 0r 2");

break;

}

}

}

  Was this answer useful?  Yes

milind patil

  • Sep 26th, 2006
 

#include<stdio.h>

#include<conio.h>

main()

{

int  a=15,b=7,r,no;

printf("1.addition  2.subraction 3.exit");

scanf("%d",&no);

switch(no)

{

case 1: //for addition

{

r=a+c;

printf("%d",r);

break;

}

case 2:

{

r=a-c;

printf("%d",r);

break;

}

default:

{

break;

}

}

}

  Was this answer useful?  Yes

praveen tiwari vaishnav mcm

  • Oct 14th, 2006
 

#include#includevoid main(){int ch;printf("enter the no");scanf("%d",&ch);switch(ch){case 1: printf(" amerika" ); break;case 1: printf("indore"); break;defoult : printf("no value"); }

  Was this answer useful?  Yes

Riquelme

  • Mar 12th, 2007
 

Brankets "{}" are not necessary in case branches, since switch-case is straight flow structure. Thanks.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions