Hello All,
I have a question and need some help with a c# console application project that asks the user to enter the number of rows to calculate and display Pascal’s Triangle. What I really need help with is how to properly format the output in the shape of a pyramid. I have completed all of coding work (i think) on the alogorithm side for the formula in c#.
I just need help with getting the output to display the results like this below on the screen:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
My visual c# code is below. I apologize for any mistakes due to me being new. I appreciate all the help. Thank you very much.
using System;
using System.Collections.Generic;
using System.Text;
public class Triangle
{
public static void Main()
{
int n;
Console.Write("Enter an integer bound: ");
n = Convert.ToInt32(Console.ReadLine());
for (int y = 0; y < n; y++)
{
int c = 1;
Console.WriteLine("\n\n");// Added only this.
for (int x = 0; x <= y; x++)
{
Console.Write(c);
Console.Write("");
c = c * (y - x) / (x + 1);
}
Console.Write(" ");
}
Console.Write(" ");
}
}