2부터 9까지의 수 중 2개를 입력받아 입력받은 수 사이의 구구단을 출력하는 프로그램을 작성하시오.
단 반드시 먼저 입력된 수의 구구단부터 아래의 형식에 맞게 출력하여야 한다.
구구단 사이의 공백은 3칸이다.
[Copy]5 3 | [Copy]5 * 1 = 5 4 * 1 = 4 3 * 1 = 3 5 * 2 = 10 4 * 2 = 8 3 * 2 = 6 5 * 3 = 15 4 * 3 = 12 3 * 3 = 9 5 * 4 = 20 4 * 4 = 16 3 * 4 = 12 5 * 5 = 25 4 * 5 = 20 3 * 5 = 15 5 * 6 = 30 4 * 6 = 24 3 * 6 = 18 5 * 7 = 35 4 * 7 = 28 3 * 7 = 21 5 * 8 = 40 4 * 8 = 32 3 * 8 = 24 5 * 9 = 45 4 * 9 = 36 3 * 9 = 27 |
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 | #include <stdio.h> int main() { int a, b,d; int c = 1; scanf("%d %d", &a, &b); if (1 < a < 10 && 1 < b < 10) { if (a > b) { for (c = 1; c <= 9; c++) { for (d= a; d >= b; d--) { printf("%d * %d =%3d ", d, c, d*c); }printf("\n"); } } else if (a < b) { for (c = 1; c <= 9; c++) { for (d =a; d <= b; d++) { printf("%d * %d =%3d ", d, c, d*c); } printf("\n"); } } else if (a == b) { for (c = 1; c <= 9; c++) { printf("%d * %d =%3d ", a, c, a*c); printf("\n"); } } } else return 1; return 0; } | cs |
'c언어' 카테고리의 다른 글
정보 올림피아드 - 634 (0) | 2016.08.01 |
---|---|
정보 올림피아드 - 549 (0) | 2016.08.01 |
정보 올림피아드 - 138 (0) | 2016.07.30 |
정보 올림피아드 - 137 (0) | 2016.07.30 |
정보 올림피아드 - 136 (0) | 2016.07.30 |