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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
0 comments :
Post a Comment