Drawing Shapes
Draws a square and a triangle with asterisks.
- Level
- Intermediate
- Topic:
- Loops
- Concepts:
- Input & output
- Para
Open in Codoritmo
Run, change and debug this example in your browser.
What you'll learn
Two nested Para loops walk through rows and columns. Escribir Sin Saltar keeps the asterisks on one line, and Escribir "" moves to the next one.
Code
Algoritmo DibujarFiguras Definir n, fila, columna Como Entero Escribir "Tamaño de las figuras:" Leer n Escribir "Cuadrado:" Para fila <- 1 Hasta n Hacer Para columna <- 1 Hasta n Hacer Escribir Sin Saltar "* " FinPara Escribir "" FinPara Escribir "Triángulo:" Para fila <- 1 Hasta n Hacer Para columna <- 1 Hasta fila Hacer Escribir Sin Saltar "* " FinPara Escribir "" FinParaFinAlgoritmoFlowchart
Each block in the flowchart matches one instruction in the code.
Sample run
This is what the program shows when it runs. The answers typed by the user are highlighted.
Tamaño de las figuras:User answer: 4Cuadrado:* * * * * * * * * * * * * * * * Triángulo:* * * * * * * * * *
Challenge
Draw an upside-down triangle: n asterisks on the first row and one on the last.
Show hint
Make the outer Para count backwards with Con Paso -1.
Related examples
Times Table
Prints the multiplication table for the number you choose.
BeginnerStore Inventory
Records the stock of each product and flags what to restock.
IntermediateBubble Sort
Sorts random numbers by swapping neighbors, and stops as soon as they're in order.
Intermediate