Pyramid Question | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

Pyramid Question

Hey there, new to coding. I was running through methods and the software had a pyramid program to follow, the code is below. The issue is that the pyramid isn't spaced properly and I'd love to understand how to fix it. Can you help me? static void DrawPyramid(ref 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) { do { Console.Write("How big would you like your pyramid: "); int z = Convert.ToInt32(Console.ReadLine()); DrawPyramid(ref z); } while (true); { } }

15th Dec 2016, 3:59 AM
Benjamin Glick
Benjamin Glick - avatar
1 Réponse
+ 1
Dude, you need to add one extra space in the Console.Write() of "j" for loop. for (int j = i; j < n; j++) { Console.Write(" "); //add two spaces instead of one space. } It will work.
16th Dec 2016, 3:54 PM
Siddharth Warwatkar
Siddharth Warwatkar - avatar