本文介绍了编写打印此类图案的程序的伪代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

分析输出模式并编写打印这种模式的程序的算法.

Analyze output pattern and write algorithm of a program that prints such a pattern.

输入4
模式:

55555
4444
333
22
1

Input 4
Pattern:

55555
4444
333
22
1

输入3
模式:

333
22
1

Input 3
Pattern:

333
22
1

过程(我想出了什么)

n  = input ("Enter a positive integer")
r= 0
while r < n
    c = (n – r) + 1
    while c > 0
        s = n – r
        print s
        c = c – 1
    end
    r = r + 1
    n = n – 1
    print end l
end

问题:我使用r代表行,使用c代表列.对于第一行,问题为c =(n – r)+1.它使第一行为n + 1,适用于随后的行.在空运行时,我会得到

Problem: I have used r for rows, and c for columns. The problem rises in c = (n – r) + 1 for first row. It makes the first row n+1, works for following rows.On dry run i get

输入3
模式:
444
22
1

Input 3
Pattern:
444
22
1

推荐答案

这应该有效:

n = input ("Enter a positive integer")
while n > 0
    c = n
    while c > 0
        print n
        c = c – 1
    end
    n = n - 1
    print end l
end

请注意变量的含义,以及如何有效地对待它们;)

Be careful about what meaning you give to your variables and therefore, how you treat them consitently ;)

这篇关于编写打印此类图案的程序的伪代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 11:21