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).

Program Code:
#include<stdio.h>
void main()
{
int a,b;
char op;
printf("\n Enter two number a,b,an operator: ");
scanf("%d %d %c",&a,&b,&op);
switch(op)
{

case'+':printf("\n Sum=%d",a+b);break;
case'-':printf("\nDifference=",a-b);break;
case'*':printf("\nProduct=",a*b);break;
case'/':printf("\nQuotient=",a/b);break;
case'%':printf("\nRemainder=",a%b);break;
default:printf("\n Please enter a valid input");
break;
}
}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

1 comments:

  1. compilation error occured , because %d is missing from subtraction part and rest.

    ReplyDelete