Created
April 9, 2011 15:50
-
-
Save am0c/911492 to your computer and use it in GitHub Desktop.
학과 스터디 숙제 - 구구단
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
| /* | |
| * 구구단 출력 프로그램: | |
| * 1. 키보드를 통하여 입력한 단을 출력합니다. | |
| * 2. 입력값 허용범위(2~9) | |
| * 3. 입력된 값이 허용범위 값을 벗어나면... | |
| * 입력 에러 메세지 출력후 다시 입력 요구를 합니다. | |
| * 4. 종료 문자(q) 입력시까지 반복합니다. | |
| * 5. 반복문은 while문과 for문 두개를 사용해서 코딩합니다. | |
| * 6. 프로그램이 실행되면 최초 한번만 실행 화면과 같이 출력합니다. | |
| * | |
| * 실행화면 첨부파일 이미지 내용: | |
| * +----------------------------------------------------------------+ | |
| * | 2 x 1 = 2 3 x 1 = 3 4 x 1 = 4 5 x 1 = 5 6 x 1 = 6 | | |
| * | 2 x 2 = 4 3 x 2 = 6 4 x 2 = 8 5 x 2 = 10 6 x 2 = 12 | | |
| * | 2 x 3 = 6 3 x 3 = 9 4 x 3 = 12 5 x 3 = 15 6 x 3 = 18 | | |
| * | 2 x 4 = 8 3 x 4 = 12 4 x 4 = 16 5 x 4 = 20 6 x 4 = 24 | | |
| * | 2 x 5 = 10 3 x 5 = 15 4 x 5 = 20 5 x 5 = 25 6 x 5 = 30 | | |
| * | 2 x 6 = 12 3 x 6 = 18 4 x 6 = 24 5 x 6 = 30 6 x 6 = 36 | | |
| * | 2 x 7 = 14 3 x 7 = 21 4 x 7 = 28 5 x 7 = 35 6 x 7 = 42 | | |
| * | 2 x 8 = 16 3 x 8 = 24 4 x 8 = 32 5 x 8 = 40 6 x 8 = 48 | | |
| * | 2 x 9 = 18 3 x 9 = 27 4 x 9 = 36 5 x 9 = 45 6 x 9 = 54 | | |
| * +----------------------------------------------------------------+ | |
| */ | |
| #include <stdio.h> | |
| #include <string.h> | |
| #define MAX_BUFLEN 256 | |
| int main(/* japh */) | |
| { | |
| char buf[MAX_BUFLEN]; | |
| unsigned int d, i; | |
| for (i = 0; i < 45; ++i) { | |
| int a = (i % 5) + 2; | |
| int b = (i / 5) + 1; | |
| printf("%d x %d = %2d ", a, b, a * b); | |
| if (a == 6) putchar('\n'); | |
| } | |
| while (1) { | |
| printf("input[2~9]: "); | |
| if (fgets(buf, sizeof(char) * MAX_BUFLEN, stdin) == 0) | |
| return; | |
| if (buf[strlen(buf)-1] == '\n') | |
| buf[strlen(buf)-1] = '\0'; | |
| if (!strncmp(buf, "q", MAX_BUFLEN)) | |
| break; | |
| if (sscanf(buf, "%d", &d) == 0) | |
| continue; | |
| if (!(d >= 2 && d <= 9)) | |
| continue; | |
| for (i = 0; i <= 9; ++i) | |
| printf("%d x %d = %2d\n", d, i, d * i); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment