Challenge: Print Number Pyramid
Swipe to start coding
Write a program that prints a number pyramid pattern using nested loops. Each row should contain numbers starting from 1 up to the row number, with leading spaces so that the numbers form a centered pyramid.
- For each row from 1 to
rows, print the correct number of leading spaces. - Print the numbers in increasing order from 1 up to the current row number, separated by spaces.
- Each row should be printed on a new line.
- The pyramid should be aligned as shown in the example output.
Løsning
The output should look like that:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Can you explain this in simpler terms?
What are the main takeaways from this?
Can you give me an example?
Awesome!
Completion rate improved to 5.56
Challenge: Print Number Pyramid
Sveip for å vise menyen
Swipe to start coding
Write a program that prints a number pyramid pattern using nested loops. Each row should contain numbers starting from 1 up to the row number, with leading spaces so that the numbers form a centered pyramid.
- For each row from 1 to
rows, print the correct number of leading spaces. - Print the numbers in increasing order from 1 up to the current row number, separated by spaces.
- Each row should be printed on a new line.
- The pyramid should be aligned as shown in the example output.
Løsning
The output should look like that:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
Takk for tilbakemeldingene dine!
single