编程输出图形
编程输出* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
#include <stdio.h> int main(void) { int i, j; char format[] = "%xc"; for(i = 0; i < 5; i++) { format[1] = i * 2 + '0'; i && printf(format, ' '); for(j = 0; j < 5; j++) printf("* "); printf("\n"); } return 0; } /* Output: * * * * * * * * * * * * * * * * * * * * * * * * * Process returned 0 (0x0) execution time : 0.016 s Press any key to continue. */
#include <stdio.h> int main(void) { int i, j; char format[] = "%xc"; for(i = 0; i < 5; i++) { format[1] = i * 2 + '0'; i && printf(format, ' '); for(j = 0; j < 5; j++) printf("* "); printf("\n"); } return 0; } /* Output: * * * * * * * * * * * * * * * * * * * * * * * * * Process returned 0 (0x0) execution time : 0.016 s Press any key to continue. */这才是我的代码啊,
#include<stdio.h> int main(void) { int flags[][9]={ {1,1,1,1,1}, {0,1,1,1,1,1}, {0,0,1,1,1,1,1}, {0,0,0,1,1,1,1,1}, {0,0,0,0,1,1,1,1,1}, }; for(int i = 0;i < 5;i++) { for(int j = 0;j < 9;j++) { if(flags[i][j] == 1) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0; }这种方法,采用标志变量的思想。思想值得学习,但是在这里似乎并不是最好的。如果一旦输出规模增大的。优势就体现出来了,可以先设置标识数组,然后依次输出就可以了。