Question #46263

write a program to implement a calculator to perform all the four basic arithmetic operations on integers.
1

Expert's answer

2014-10-01T01:26:05-0400

Problem.

write a program to implement a calculator to perform all the four basic arithmetic operations on integers.

Solution.

#include <stdio.h>
int main() {
    int operand1;
    int operand2;
    char operation;
    scanf("%d %c %d", &operand1, &operation, &operand2);
    // Addition
    if (operation == '+') {
        printf("Result: %d", operand1 + operand2);
    }
    // Subtraction
    if (operation == '-') {
        printf("Result: %d", operand1 - operand2);
    }
    // Multiplication
    if (operation == '*') {
        printf("Result: %d", operand1 * operand2);
    }
    // Division
    if (operation == '/') {
        printf("Result: %.3f", (float) operand1 / operand2);
    }
    return 0;
}

Result

123 + 1223

Result: 1346

124 - 12

Result: 112

12 * 133

Result: 1596

143 / 24

Result: 5.958

http://www.AssignmentExpert.com/</stdio.h>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!
LATEST TUTORIALS
APPROVED BY CLIENTS