/* Unusual Triangle */ #include <stdio.h> #include <stdlib.h> #define LEN 256 int main(void) { long n; long i, j; int upperRecord[LEN]; int curRecord[LEN]; char *outputStr[2] = {" ","* "}; while(scanf("%d", &n)!= EOF && n != 0) { printf("The Triangle Scale is %d:\n", n); curRecord[0] = 1; //初始化第一层花印数组 curRecord[1] = 9; //结束标志 //测试‘\0‘结束标志 i=0; while(curRecord[i] != ‘\0‘) i++; if(curRecord[i] == ‘\0‘) printf("Int Array[%d] end of \\0\n", i); n = 1<<(n-1); //确定规模 for(i=1; i<=n; i++) //循环打印 { for(j=i;j<n;j++) //打印前面的空格 printf(*outputStr+1); for(j=0; curRecord[j] < 2; j++) //打印花印 if(curRecord[j] == 1) printf(*(outputStr+1)); else printf(*outputStr); printf("\n"); for(j=0; curRecord[j] < 2; j++) //复制当前层花印 upperRecord[j] = curRecord[j]; upperRecord[j] = 9; for(j=0; upperRecord[j+1] < 2; j++) //产生下一层花印 curRecord[j+1] = upperRecord[j] ^ upperRecord[j+1]; curRecord[j+1] = 1; curRecord[j+2] = 9; } } return EXIT_SUCCESS; } #ifdef RESULT E: cd Cprogram gcc Unusual_Triangle.c echo 1 2 3 4 | a.exe (echo #ifdef RESULT & doskey /history & echo 1 2 3 4 | a.exe & echo #endif) >> Unusual_Triangle.c The Triangle Scale is 1: Int Array[18] end of \0 * The Triangle Scale is 2: Int Array[18] end of \0 * * * The Triangle Scale is 3: Int Array[18] end of \0 * * * * * * * * * The Triangle Scale is 4: Int Array[2] end of \0 * * * * * * * * * * * * * * * * * * * * * * * * * * * #endif
时间: 2024-10-22 09:46:22