Last active
October 9, 2024 12:09
-
-
Save lry127/095e9e0e863e68c7388581e6e411064a to your computer and use it in GitHub Desktop.
main.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(void) { | |
int operand1, operand2; | |
char operator; | |
scanf("%d %c %d", &operand1, &operator, &operand2); | |
int result = 0; | |
char* print_out = NULL; | |
switch (operator) { | |
case '+': | |
result = operand1 + operand2; | |
break; | |
case '-': | |
result = operand1 - operand2; | |
break; | |
case '*': | |
result = operand1 * operand2; | |
break; | |
case '/': | |
result = operand1 / operand2; | |
break; | |
case '%': | |
result = operand1 % operand2; | |
break; | |
default: | |
print_out = "ERROR"; | |
} | |
char str[sizeof(int) * 4]; | |
if (!print_out) { | |
sprintf(str, "%d", result); | |
print_out = str; | |
} | |
printf(print_out); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment