/*Write a c program to perform arithmetic
operation using switch statement */
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a,b, sum=0,product=0,diff=0,division=0,op;
printf("Enter the two numbers :\n");
scanf("%d%d",&a,&b);
printf("1.Addition\t2.Subtraction\t3.Multiplication\t4.Division");
printf("\nEnter the choice :\n");
scanf("%d",&op);
switch(op)
{
case 1: sum=a+b;
printf("%d + %d = %d \n",a,b,sum);
break;
case 2: diff=a-b;
printf("%d - %d = %d \n",a,b,diff);
break;
case 3: product=a*b;
printf("%d * %d = %d \n",a,b,product);
break;
case 4: division=a/b;
printf("%d / %d = %d \n",a,b,division);
break;
default :
printf("Invalid choice\n");
break;
}
return 0;
}
No comments:
Post a Comment