首页 > 代码库 > 打印特殊三角形
打印特殊三角形
/* Unusual Triangle */#include <stdio.h>#include <stdlib.h>#define LEN 256int 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 Cprogramgcc Unusual_Triangle.cecho 1 2 3 4 | a.exe(echo #ifdef RESULT & doskey /history & echo 1 2 3 4 | a.exe & echo #endif) >> Unusual_Triangle.cThe 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
打印特殊三角形
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。