C# Making a Pyramid | Sololearn: Learn to code for FREE!

C# Making a Pyramid

How do the for loops work in the C# "Making a Pyramid" lesson? This is the code: static void DrawPyramid(int n) { for (int i=1; i<=n; i++) { for (int j=i; j<=n; j++) { Console.Write(" "); } for (int k=1; k<=2*i-1; k++) { Console.Write("*"+" "); } Console.WriteLine(); } } static void Main(string[] args) { DrawPyramid(5); }

4th Jan 2023, 6:18 PM
Giovanni Paolo Balestriere
Giovanni Paolo Balestriere - avatar
1 Respuesta
+ 2
The best way that you can find out yourself is by adding some other outputs in each loop. You could put an output with "for loop i" at the beginning, see where it begins/ends. See if that starts to show you what's going on.
4th Jan 2023, 8:37 PM
Ausgrindtube - avatar