BASIC CALCULATOR
Problem Description
Write a program to simulate a basic calculator. [+,-,*,/,%]. Use switch statement.
Input Format:
The first line of the input consists of an integer which corresponds to a. The second line of the input consists of a character which corresponds to the operator. The third line of the input consists of an integer which corresponds to b.
Output format:
Output consists of a single line [a op b]. Refer to sample output for details.
CODING ARENA::
#include <stdio.h>
int main()
{
int a, b;
char c;
scanf("%d %c %d",&a,&c,&b);
switch (c)
{
case '+':
printf("Answer=%d",a+b);
break;
case '-':
printf("Answer=%d",a-b);
break;
case '*':
printf("Answer=%d",a*b);
break;
case '/':
printf("Answer=%d",a/b);
break;
}
return 0;
}
Test Case 1
Input (stdin)3+5
Expected Output
Answer=8
Test Case 2
Input (stdin)12-6
Expected Output
Answer=6
No comments:
Post a Comment