打印特殊三角形

/* 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

打印特殊三角形的相关文章

用c语言打印一个三角形

#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>#include<stdlib.h>#include<math.h>#include<time.h> int main(){ int n; printf("请输入想要打印三角形的高度:\n"); scanf("%d", &n); for (int i = 0; i &l

打印*个三角形

<script> function stars(n){ ele=document.getElementById("star"); var i,j; var line=""; for(j=0;j<n;j++){ for(i=0;i<2*j+1;i++){ line += "*";//打印每一行* } line = line+"<br/>";//给每行加上一个换行标签 } ele.innerHT

c语言打印字母三角形

#include <stdio.h> int main(int argc, const char * argv[]) { char cost,top; cost=getchar(); if (cost>='a'&&cost<='z') { top='a'; }else if (cost>='A'&&cost<='Z') { top='A'; } int h=cost-top; for (int j=0; j<=h; j++) { f

c语言实践 打印数字三角形

效果如下图: 思路就是外层循环控制要打印的行数,里层循环控制每行打印的数字个数. int val = 65; for (int i = 0; i < 6; i++) { for (int j = 0; j < i+1 ; j++) { printf("%d ",val); val++; } printf("\n"); } 原文地址:https://www.cnblogs.com/yfish/p/9718173.html

c语言实践打印字母三角形

效果如下: int main(void) { char ch = 'A';//当前要打印的字符 int count = 1;//每行要打印字符的个数 for (int i = 0; i < 6; i++,count++) { for (int j = 0; j < count; j++,ch++) { printf("%c",ch); } printf("\n"); } return 1; } 外层循环的count++能不能放到里层循环ch++ 的后面?

JAVA打印空三角形

1 import java.util.*;//导入java包 2 public class Sang { 3 //这是主函数程序的入口 4 public static void main(String[] args) { 5 System.out.println("请输入要打印的行数"); 6 Scanner sc = new Scanner(System.in); 7 int rows = sc.nextInt(); 8 for(int i = 1;i <= rows;i++)

打印数字三角形

题目描述 打印如下图形输入n(1<=n=<10),打印特殊三角 输入 4 输出 1  2  3  43  5  78  1220 样例输入 Copy 4 n=int(input()) list_s=[] for i in range(1,n+1): list_s.append(i) z=1 for i in range(n): if i == 0 : for j in range(1,n): print("%-3d"%j,end="") print(j+

打印直接三角形

  #!/bin/sh i=1 while [ $i -lt 10 ] ; do j=1 while [ $j -le $i ] ; do echo -n x j=$(($j+1)) done echo i=$(($i+1)) done exit

打印空心三角形

for i in range(1,7): for j in range(1,7-i): print(" ",end="") for k in range(1,2*i-1+1): if k==1 or k==2*i-1 or i==6: print("*",end="") else: print(" ",end="") print() 原文地址:https://www.cnblogs.co