문제

I need to write a program that reads an command prompt argument (int n) that then outputs a cross made of Xs depending on the number, so an arg of 3 would output this

http://i.imgur.com/a441t0X.png

X would increase or decrease depending on the number in the arg

im not really sure how to go about this

도움이 되었습니까?

해결책

Here's an algorithm (not actual code) for printing the cross (assuming the argument passed in is referred to as count):

LOOP(count times)
    LOOP(count times)
        PRINT space_character
    ENDLOOP
    PRINT "X"
    PRINT newline
ENDLOOP

LOOP(count times)
    PRINT "X"
ENDLOOP

PRINT " "

LOOP(count times)
    PRINT "X"
ENDLOOP

PRINT newline

LOOP(count times)
    LOOP(count times)
        PRINT space_character
    ENDLOOP
    PRINT "X"
    PRINT newline
ENDLOOP

다른 팁

There are different ways to do this, the best way to start though is to break it up into loops.

So there would be a loop to create the first vertical section. Then one to produce the second horizontal and finally one to produces the last vertical section

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top