-->

Facebook

Jasper Roberts - Blog

Tuesday, March 31, 2015

Write a C Program to Add, subtract and multiply two nos. using switch statement.



PRACTICAL-SET-4
3.  Add, subtract and multiply two nos. using switch statement.


#include<stdio.h>
#include<stdio.h>

void main()
{
int num1,num2, choice;
clrscr();

printf("Enter the value of number1 : ");
scanf("%d",&num1);

printf("Enter the value of number2 : ");
scanf("%d",&num2);


printf("\n 1. Addition, ");
printf("\n 2. Substraction,");
printf("\n 3. Multiplication,  ");
printf("\n 4. Division.");

printf("\n Enter Your Choice:");
scanf("%d",&choice);

switch(choice)
{
case 1:
printf("%d + %d = %d",num1, num2, num1+num2);
break;

case 2:
printf("%d - %d = %d",num1, num2, num1-num2);
break;

case 3:
printf("%d * %d = %d",num1, num2, num1*num2);
break;
case 4:
printf("%d / %d = %d",num1, num2, num1/num2);
break;

default:
printf("Please enter the correct choise!!");
}
getch();

}

OUTPUT:
Enter the value of number1 : 10
Enter the value of number2 : 10
 1. Addition,
 2. Substraction,
 3. Multiplication,
 4. Division.

Enter Your Choice:1
10 + 10 = 20

No comments:

Post a Comment