Skip to content

Instantly share code, notes, and snippets.

@lry127
Last active October 9, 2024 12:09
Show Gist options
  • Save lry127/095e9e0e863e68c7388581e6e411064a to your computer and use it in GitHub Desktop.
Save lry127/095e9e0e863e68c7388581e6e411064a to your computer and use it in GitHub Desktop.
main.c
#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