5. write a C program which takes two integers operands and one operand from the user,perform the opearation and prints the result.


C program which takes two integers operands and one operand from the user,perform the opearation and prints the result(Using switch).

Source Code:

#include<stdio.h>
int main()
{
char op;
int num1,num2;
printf("enter the operator: ");
scanf("%c",&op);
printf("enter the 2 numbers:");
scanf("%d %d",&num1,&num2);
switch(op)
{
case'+':
printf("%d + %d = %d",num1,num2,num1+num2);
break;
case'-':
printf("%d - %d = %d",num1,num2,num1-num2);
break;
case'*':
printf("%d * %d = %d",num1,num2,num1*num2);
break;
case'/':
printf("%d / %d = %d",num1,num2,num1/num2);
break;
default:
printf("enter operator only");
break;
}
}

OutPut:

enter the operator: +
enter the 2 numbers:40
50
40 + 50 = 90

No comments:

Post a Comment