You are on page 1of 2

Practical-3(Part-2)

AIM: Write a C program, which takes two integer operands and one operator
from the user, performs the operation and then prints the result. (Consider the
operators and use switch statement).
Enter the code:
#include<stdio.h>
int main()
{
char ch;
int a,b,c;
printf("Enter the (+,-,/,%,*)");
scanf("%c",&ch);
printf("Enter the Value of a :");
scanf("%d",&a);
printf("Enter the Value of b :");
scanf("%d",&b);
switch(ch)
{
case'+':a+b;
printf("%d",c);
break;
case'-':a-b;
printf("%d",c);
break;
case'/':a/b;
printf("%d",c);
break;
case'%':a%b;
printf("%d",c);
break;
case'*':a*b;
printf("%d",c);
break;
default:printf("Invalid operator");
}
return 0;
}
Output:

You might also like