Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PascalTriangle
- {
- class Program
- {
- static List<long> pascalList = new List<long> { 0, 1, 0 };
- static List<long> tempList = new List<long>();
- static List<List<long>> pascalTriangle = new List<List<long>>();
- static int LastRowCount=0;
- static int rowsRequired=0;
- static void Main(string[] args)
- {
- Console.WriteLine("Please enter the rows");
- rowsRequired = Convert.ToInt32(Console.ReadLine());
- for (int iteration = 0; iteration < rowsRequired; iteration++)
- {
- IEnumerator<long> enumeratorTwo = pascalList.GetEnumerator();
- enumeratorTwo.MoveNext();
- tempList.Add(0);
- foreach (long ele in pascalList)
- {
- if (enumeratorTwo.MoveNext())
- tempList.Add(ele + enumeratorTwo.Current);
- }
- tempList.Add(0);
- pascalList = tempList.ToList<long>();
- pascalTriangle.Add(pascalList.Where(ele => ele != 0).ToList<long>());
- tempList.Clear();
- }
- LastRowCount = pascalTriangle[pascalTriangle.Count - 1].Count();
- foreach (List<long> psclRow in pascalTriangle)
- {
- for (long i = 0; i < LastRowCount; i++)
- Console.Write(" ");
- foreach (long psclRowEle in psclRow)
- Console.Write(psclRowEle +" ");
- Console.WriteLine();
- LastRowCount--;
- }
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement