Preloader
PseInt
  • Estimated reading time: 1 Minute

How to print the border of an empty square with asterisks in PseInt

How to print the border of an empty square with asterisks in PseInt

For many exercises of practice and understanding on cycles defined in programming, you will need to do exercises that although they have no real life implication are quite useful to understand the cycles in their entirety. One of the most common is to create the figure of a square, however without filling, only its edges. This can be achieved with a cycle within another cycle easily and using the instruction Escribir Sin Saltar in order to print characters in a row on the same line:

Algoritmo BordeCuadrado
	Definir numeroLados, contador Como Entero
	
	Escribir "Enter the length of the sides:"
	Leer numeroLados
	
	Para a<-1 Hasta numeroLados Con Paso 1 Hacer
		Para b<-1 Hasta numeroLados Con Paso 1 Hacer
			Si a == 1 O a == numeroLados O b == 1 O b == numeroLados Entonces
				Escribir Sin Saltar "* "
			SiNo
				Escribir Sin Saltar "  "
			FinSi
		Fin Para
		
		Escribir ""
	Fin Para
FinAlgoritmo

Happy coding ❤️!

Related articles
How to resolve PseInt exception: ERROR 273 Debe haber un Proceso
10 Apr, 2021
  • Estimated reading time: 2 Minutes
How to print the first N numbers of the Fibonacci series in PseInt
20 Oct, 2020
  • Estimated reading time: 1 Minute
How to print the first N multiples of a number in PseInt
20 Oct, 2020
  • Estimated reading time: 1 Minute
How to determine if a number is positive or negative in PseInt
20 Oct, 2020
  • Estimated reading time: 1 Minute
Our Sponsors

Our blog is proudly supported by industry-leading sponsors.