题目如下,稍后再更新配套说明,zhanggai说他要写题解,等他的了。或者有哪个同学觉得自己写的好的发给我,我更新
0 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 |
1.打印下列图形 |***********| |***********| |***********| |***********| 2.打印下列图形 |* * * * * *| | * * * * * | |* * * * * *| | * * * * * | 3.在2的基础上,自定义输入字符c,打印 |c c c c c c| | c c c c c | |c c c c c c| | c c c c c | 例如,如果输入a,则打印 |a a a a a a| | a a a a a | |a a a a a a| | a a a a a | 4.在3的基础上,自定义输入行号n(n >= 1), 如果n是奇数 打印|c c c c c c| 如果n是偶数 打印| c c c c c | 如果n是负数 提示输入错误 5.在2的基础上,自定义输入字符c,个数n,行数m 打印奇数行n个c,偶数行n-1个c |
答案如下
0 1 2 3 4 5 6 7 8 9 |
#include <stdio.h> // http://blog.hylstudio.cn/archives/686 int main() { printf("|***********|\n"); printf("|***********|\n"); printf("|***********|\n"); printf("|***********|\n"); return 0; } |
0 1 2 3 4 5 6 7 8 9 |
#include <stdio.h> // http://blog.hylstudio.cn/archives/686 int main() { printf("|* * * * * *|\n"); printf("| * * * * * |\n"); printf("|* * * * * *|\n"); printf("| * * * * * |\n"); return 0; } |
0 1 2 3 4 5 6 7 8 9 10 11 12 |
#include <stdio.h> // http://blog.hylstudio.cn/archives/686 int main() { char input = '*'; scanf("%c", &input); printf("|%c %c %c %c %c %c|\n", input, input, input, input, input, input); printf("| %c %c %c %c %c |\n", input, input, input, input, input); printf("|%c %c %c %c %c %c|\n", input, input, input, input, input, input); printf("| %c %c %c %c %c |\n", input, input, input, input, input); return 0; } |
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include <stdio.h> // http://blog.hylstudio.cn/archives/686 int main() { char input = '*'; int lineNum = 1; //input character scanf("%c", &input); //input lineNum scanf("%d", &lineNum); //check lineNum range if (lineNum < 1) { printf("input n error, n should greater than equal 1!\n"); return -1; } if (lineNum % 2 == 1) { printf("|%c %c %c %c %c %c|\n", input, input, input, input, input, input); } else { printf("| %c %c %c %c %c |\n", input, input, input, input, input); } return 0; } |
0 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 |
#include <stdio.h> // http://blog.hylstudio.cn/archives/686 int main() { char input = '*'; int charPerLine = 6; int lineNum = 1; int lines = 4; // input character scanf("%c", &input); // input charPerLine scanf("%d", &charPerLine); // input lines scanf("%d", &lines); // check lineNum range if (charPerLine < 1) { printf("input n error, n should greater than equal 1!\n"); return -1; } // check lines range if (lines <= 0) { printf("input m error, n should greater than equal 1!\n"); return -1; } for (lineNum = 1; lineNum <= lines; lineNum++) { printf("|"); if (lineNum % 2 == 1) { for (int i = 0; i < charPerLine - 1; i++) { printf("%c ", input); } printf("%c", input); } else { printf(" ", input); for (int i = 0; i < charPerLine - 1; i++) { printf("%c ", input); } } printf("|\n"); } return 0; } |
0 Comments