Program for doing arithmetic operation on two integers based on an operator

0
193
#include<stdio.h>
#include<conio.h>
void main()
{
 int a,b;
 char op;   /* for storing operator +,-,*,/,% */
 clrscr();
 printf("\n Enter an arithmetic operator +, -, *, /, % \n");
 op=getchar();
 printf("\n enter two integers \n");
 scanf("%d%d",&a,&b);
 switch(op)
 {
  case '+':
           printf("\n sum=%d \n",\n",a+b);
           break;
  case '-':
           printf("\n difference=%d \n",a-b);
           break;
  case '*':
           printf("\n product=%d \n",a*b);
           break;
  case '/':
           printf("\n quiescent=%d \n",a/b);
           break;
  case '%':
           printf("\n remainder=%d \n",a%b);
           break;
  default:
          printf("\n given operator is not an arithmetic operator \n");
 }
getch();
}
 Output 1:
 Enter an arithmetic operator +,-,*,/,%
 +
 enter two integers
 20 4
 sum is 24
 Output 2:
 Enter an arithmetic operator =,-,*,/,%
 =
 enter two integers
 20 4
 given operator is not an arithmetic operator

 

 

Program for doing arithmetic operation on two integers based on an operator arithmetic operation program in c perform all arithmetic operation perform all arithmetic operation in cA program which perform all arithmetic operation

LEAVE A REPLY

Please enter your comment!
Please enter your name here