Wednesday, February 26, 2014

Use of switch statement


By on 3:20 AM

Switch statement is mainly used
if we have to make multiple descision. I have given one example of using switch statement to make clear about the use of switch statement.
The main source code of the program is given below:

#include<stdio.h>
#include<conio.h>
int main()
{
int n;
float a,b, sum,diff,product;
top:
printf("enter your choice:\n");
printf("1.addition,2.subtraction,3.product\n");
scanf("%d",&n);
switch(n);
case 1:
printf("enter any two numbers:\n");
scanf("%f%f"&a,&b);
sum=a+b;
printf("the sum is %f:",sum);
break;
case 2:
printf("enter any two numbers:\n");
scanf("%f%f"&a,&b);
diff=a-b;
printf("the difference is %f:",diff);
break;
case 2:
printf("enter any two numbers:\n");
scanf("%f%f"&a,&b);
product=a*b;
printf("the product is %f:",product);
break;
default:
printf("enter number between 1 and 3:");
goto top;
getch();
return 0;
}

About Authors

Aakash and Shreeram are owners of this website. Both are engineering student. Aakash is studying computer engineering and has passion with blogs and love to play with it while Shreeram is studying civil engineering and has dream of implementing technology in practical life.

0 comments :

Post a Comment