visualg ladder break line

Asked

Viewed 1,062 times

2

I’m having trouble with the code to break the line. I need to create a ladder that looks like below:

    #
   ##
  ###
 ####
#####

If I write ("#") it breaks the line, but the end result is like this:

     #
    #
#
   #
#
#
  #
#
#
#
 #
#
#
#
#

Does anyone know what adjustment I should make ? with the current code the result is getting that way:

Quantidade de degraus: 5
     #    ##   ###  #### #####

Algoritmo "escada"
Var
p, x1, x, lin, col, degr: inteiro

Inicio
Escreva ("Quantidade de degraus: ")
Leia (degr)
x:=degr
x1:=1
Para lin de 1 ate degr passo 1 faca
Para col de 1 ate x passo 1 faca
escreva(" ")
Fimpara
x:=x-1
Para p de 1 ate x1 passo 1 faca
escreva("#")
Fimpara
x1:=x1+1
escreva( )
Fimpara
fimalgoritmo

thanks in advance !!

  • I didn’t understand the variable x ai. I’m new in Programming Logic.

1 answer

0


Stayed like this:

Algoritmo "escada"
   Var
   p, x1, x, lin, col, degr: inteiro
   Inicio
   Escreva ("Quantidade de degraus: ")
   Leia (degr)
   degr:=degr + 1

   Para lin de degr ate 0 passo -1 faca
        Para col de 1 ate (degr - x) passo 1 faca
             escreva(" ")
        Fimpara
        Para col de 1 ate x passo 1 faca
             escreva("#")
        Fimpara
        x:=degr - lin
        escreval("")
   Fimpara
fimalgoritmo

Any doubt just comment here that I answer. :)

  • Thank you so much !!! It worked perfectly here!

  • the answer is exact friend , I just wanted to understand how the variables work where each one represents the line break ...

  • I read the variable degr, I add 1 in it, because my structure of repetition of degr up to 0, by putting +1 I certify that it really goes up to the desired number. The variable lin is an accountant, she will start from degr and goes to 0, use it to print each line. In the internal repeat structure use a variable col from 1 to degr - x where x is degr - lin as each line will display a space ( ) less.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.