//program to get sum or product or difference or quotient of two numbers using switch.
#include<stdio.h>
#include<conio.h>
void main()
{
int choice;
int number1,number2;
printf("enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("we are going to sum two numbers\n");
printf("enter two numbers\n");
scanf("%d%d",&number1,&number2);
printf("the sum=%d",number1+number2);
break;
case 2:
printf("we are going to get difference of two numbers\n");
printf("enter two numbers\n");
scanf("%d%d",&number1,&number2);
printf("the sum=%d",number1-number2);
break;
case 3:
printf("we are going to get product of two numbers\n");
printf("enter two numbers\n");
scanf("%d%d",&number1,&number2);
printf("the sum=%d",number1*number2);
break;
case 4:
printf("we are going to get quotient of two numbers\n");
printf("enter two numbers\n");
scanf("%d%d",&number1,&number2);
printf("the sum=%d",number1%number2);
break;
default:
printf("sorry, not a valid input\n");
printf("thank u, terminating....\n");
}
getch();
}
note:
here, you can use 'char' data type instead 'int' and you can input data before switch statement as well.
#include<stdio.h>
#include<conio.h>
void main()
{
int choice;
int number1,number2;
printf("enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("we are going to sum two numbers\n");
printf("enter two numbers\n");
scanf("%d%d",&number1,&number2);
printf("the sum=%d",number1+number2);
break;
case 2:
printf("we are going to get difference of two numbers\n");
printf("enter two numbers\n");
scanf("%d%d",&number1,&number2);
printf("the sum=%d",number1-number2);
break;
case 3:
printf("we are going to get product of two numbers\n");
printf("enter two numbers\n");
scanf("%d%d",&number1,&number2);
printf("the sum=%d",number1*number2);
break;
case 4:
printf("we are going to get quotient of two numbers\n");
printf("enter two numbers\n");
scanf("%d%d",&number1,&number2);
printf("the sum=%d",number1%number2);
break;
default:
printf("sorry, not a valid input\n");
printf("thank u, terminating....\n");
}
getch();
}
note:
here, you can use 'char' data type instead 'int' and you can input data before switch statement as well.
No comments:
Post a Comment