반응형
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> void main() { int num1, num2; char oper; printf("Enter the 1st number : "); scanf("%d", &num1); printf("Enter operator : "); scanf("%c", &oper); printf("Enter the 2nd number : "); scanf("%d", &num2); printf("%d %c %d = %d \n", num1, oper, num2, num1 + num2); } | cs |
operator의 문제점
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> int main(void) { int x, y; char oper; char select; do { printf("Input the 1st value : "); scanf("%d", &x); printf("Input operator(+, -, *, /) : "); rewind(stdin); scanf("%c", &oper); printf("Input the 2nd value : "); scanf("%d", &y); switch (oper) { case '+': printf("result = %d %c %d = %d \n", x, oper, y, x + y); break; case '-': printf("result = %d %c %d = %d \n", x, oper, y, x - y); break; case '*': printf("result = %d %c %d = %d \n", x, oper, y, x * y); break; case '/': printf("result = %d %c %d = %.2f \n", x, oper, y, (float)x / y); break; default: puts("You entered wrong operator!"); break; } printf("Do you want to continue? : "); rewind(stdin); scanf("%c", &select); } while (select == 'Y' || select == 'y'); return 0; } | cs |
반응형