C 언어: 수학+_000003
C언어: 수학연산 000003
/// 연산
더하기 (0 ~ 9)
/// 예제
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | #include <stdio.h> #include <stdlib.h> #include <time.h> #define MAX_Q 10 // 최대 질문 개수 #define CONVERSATION 1 #define CLOSING 0 static unsigned int rand_num1 = 0; static unsigned int rand_num2 = 0; static unsigned int ans = 0; static char input = 'r'; void func_question(void); void func_answer(void); void func_result(void); int main(void) { int question = 0; int status = 0; int rt_int; do { printf("대화(1) | 종료(1 이외의 수): "); rt_int = scanf("%d", &status); if (getchar() != '\n') { // for scanf() status = 1aaa, aaa ... while (getchar() != '\n'); status = CLOSING; } if (status == CONVERSATION) { func_question(); func_answer(); func_result(); } else { printf("대화를 종료하겠습니다. 만나서 즐거웠습니다.\n"); exit(EXIT_FAILURE); } question++; } while(question 9); printf("질문: %d 더하기 %d (은/는) 몇 입니까? ", rand_num1, rand_num2); } void func_answer(void) { int rt_int; printf("대답: "); rt_int = scanf("%u", &ans); if (getchar() != '\n') { // for scanf() ans = 1aaa, aaa ... while (getchar() != '\n'); input = 'w'; // w = wrong } } void func_result(void) { if (input != 'w') { if (ans == (rand_num1 + rand_num2)) printf("%d 더하기 %d (은/는) %d(이/가) 맞습니다.\n", rand_num1, rand_num2, ans); else printf("%d 더하기 %d (은/는) %d(이/가) 아닙니다.\n", rand_num1, rand_num2, ans); } else { puts("잘못 입력하셨습니다."); } input = 'r'; // r = right puts(""); } | cs |
* 실행환경: Linux(5.7.6-x86_64-linode136)
* 컴파일러: gcc (Ubuntu 6.5.0-2ubuntu1~14.04.1) 6.5.0 20181026
- 당신을 응원합니다. -
댓글
댓글 쓰기