Public Group

# C# Question

This topic is 3820 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
This sounds like a homework question, so we can't give you a full answer.

To start with, do you know how loops work?

##### Share on other sites
You may also want to look into recursion as well.

##### Share on other sites
Will probably need nested loops here...

##### Share on other sites
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

##### Share on other sites
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];

##### Share on other sites
Generate the triangle then use the user's input to print n+1 rows...

##### Share on other sites
Quote:
 Original post by thre3deeGenerate 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#.

##### Share on other sites
Quote:
 Original post by guzumbaIts a challenge in my book im learning.

Just curious, what book are you using?

##### Share on other sites
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 &lt; input; i++)        {            for (int j = 0; j &lt; 10; j++)            {                rowArray[i, j] = i * j;            }        }    }}

1. 1
2. 2
Rutin
31
3. 3
4. 4
5. 5
khawk
14

• 11
• 11
• 23
• 10
• 9
• ### Forum Statistics

• Total Topics
633647
• Total Posts
3013108
×