C# Question

Started by
14 comments, last by Nypyren 15 years, 9 months ago
Im wanting to print Pascal’s Triangle from user input. So if I ask the user for a positive number and he types 4 I want to print. 0 1 1 1 1 2 1 2 1 3 1 3 3 1 4 1 4 6 4 1 and if 2 was typed then only print the first 3 rows. I would like any help or suggestions please. Thanks, Andy
Advertisement
This sounds like a homework question, so we can't give you a full answer.

To start with, do you know how loops work?
You may also want to look into recursion as well.
Will probably need nested loops here...
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
This is not a homework question. Its a challenge in my book im learning. I just need some starting tips. And yes I know loops and nested loops but its got something to do with arrays cause that was the chapter I just read.

Thanks,
Andy
Hint: Use the variable that's being incremented by a for loop to read from one array and write to the next.

You also have to be able to make arrays based on which row # you're on.

To make an array however large you need it to be:

int[] rowArray;// later... maybe in a loop...rowArray = new int[numberOfSlots];
Generate the triangle then use the user's input to print n+1 rows...
Quote:Original post by thre3dee
Generate the triangle then use the user's input to print n+1 rows...


The triangle is infinite. This is C# we're talking about, not F#.
Quote:Original post by guzumba
Its a challenge in my book im learning.


Just curious, what book are you using?
In this code im messing with Arrays but how do I print the Arrays?

using System;public class proj3{    public static void Main()    {        Console.Write("Enter a positive integer: ");        int input = Convert.ToInt32(Console.ReadLine());        int[,]rowArray = new int[input,input];        for (int i = 0; i < input; i++)        {            for (int j = 0; j < 10; j++)            {                rowArray[i, j] = i * j;            }        }    }}

This topic is closed to new replies.

Advertisement