C 语言 空心梯形 输入行数 n 值和首数字字符,在屏幕上输出由数字围起的高和下底宽度均 n 的空心梯形.要求 :输出的数字是循环的,即输出数字 9 后再输出的数字是 0.输入 5 5↵输出 5 6 7 8

来源:学生作业帮助网 编辑:作业帮 时间:2024/06/30 06:45:44
C 语言 空心梯形 输入行数 n 值和首数字字符,在屏幕上输出由数字围起的高和下底宽度均 n 的空心梯形.要求 :输出的数字是循环的,即输出数字 9 后再输出的数字是 0.输入 5 5↵输出 5 6 7 8
xWn6~" _[w?{tsԑTKK`lh&Ⱥb+ YЭ6}v~FgIm'm0l-~59 :[O;cz_?xw[+Wd_)ho\"2Xnl3G{krongqsL< kW ꩵwj")|9s@A 4 )=ʂVZD FDcyPyJ q1B|AF I U*㮫3"L"׬-;_J_{a)-:`Dq9~5Mf교w99!ثVGcW=7ܐNEh+}gY2x *U113-f9!C<k$Jnoʢ-)Gâ|iA&)\i>;$Qb[a 3F2mKwGfN'EJI23ϏcHȡiE`ǣʘE։\.'q! Ry G*,KMfAGnfIЃtgQ yy,ꋽErl~z6ov7G$Ju8Ώ o3{=ݵzaGkvuaDbM3lG=SwivQTzrs!I~9%cPʉ6tzOؓCA^o=~D>ct-Ay]h|J '  /􂂡#^03Y5 aJ8Bh-K:xVdSPm

C 语言 空心梯形 输入行数 n 值和首数字字符,在屏幕上输出由数字围起的高和下底宽度均 n 的空心梯形.要求 :输出的数字是循环的,即输出数字 9 后再输出的数字是 0.输入 5 5↵输出 5 6 7 8
C 语言 空心梯形 输入行数 n 值和首数字字符,在屏幕上输出由数字围起的高和下底宽度均 n 的空心梯形.
要求 :输出的数字是循环的,即输出数字 9 后再输出的数字是 0.
输入 5 5↵
输出
5 6 7 8 9 0 1 0 9 8 7 6 5
6 6
7 7
8 8
9 0 1 0 9↵

C 语言 空心梯形 输入行数 n 值和首数字字符,在屏幕上输出由数字围起的高和下底宽度均 n 的空心梯形.要求 :输出的数字是循环的,即输出数字 9 后再输出的数字是 0.输入 5 5↵输出 5 6 7 8

#include "stdio.h"

/* 画rows行首数字为start的实心梯形 */

void drawHollowEchelon(int rows, int start)

{

    int i, j, k;

    int value;

    

    /* 输出上底 */

    for(i=0; i<=(3*rows-3)/2; i++)

        printf("%d", (start+i)%10);

    for(i=0; i<=(3*rows-4)/2; i++)

        printf("%d", (start+(3*rows-3)/2+(rows%2==0?0:-1)-i+10)%10);

    printf("\n");

    for(i=0; i<rows-2; i++)

    {

        for(j=0; j<=i; j++)

            printf("%c", ' ');

        printf("%d", (start+i+1)%10);

        for(j=0; j<3*rows-2*i-6; j++)

            printf("%c", ' ');

        printf("%d\n", (start+i+1)%10);

    }

    /* 输出下底 */

    for(i=0; i<rows-1; i++)

        printf("%c", ' ');

    for(i=0; i<(rows+1)/2; i++)

        printf("%d", (start+rows-1+i)%10);

    for(i=0; i<rows/2; i++)

        /*printf("%d", (start+(3*rows-3)/2-i+10)%10); */

        printf("%d", (start+(3*rows-3)/2+(rows%2==0?0:-1)-i+10)%10);

    printf("\n");

}

void main()

{

    int rows;  /* [1, 24], 超过24行时一屏无法全部显示 */

    int start;  /* [0, 9] */

    do

    {

        printf("input rows and start figure (such as 5 5) : ");

        scanf("%d%d", &rows, &start);

    }while(rows<0 || rows>24 || start<0 || start>9);

    drawHollowEchelon(rows, start);

}

输出结果: