How does this C for-loop print text-art pyramids?

后端 未结 10 1907
灰色年华
灰色年华 2021-02-05 04:24

This is my first time posting in here, hopefully I am doing it right.

Basically I need help trying to figure out some code that I wrote for class using C. The purpose o

10条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 05:11

    You should use indentatation to make your code more readable and therefore easier to understand.

    What your code does is print user_i lines that consist of user_i-tall+1 spaces and then tall+1 hashes. Because the iteration index tall increases with every pass this means that one more hash is printed. They are right aligned because a space is left out as well. Subsequently you have 'growing' rows of hashes that form a pyramid.
    What you are doing is equivalent to this pseudo code:

    for every i between 0 and user_i do:
        print " " (user_i-i+1) times
        print "#" (i+1) times
    

提交回复
热议问题