Jump to content
  • Advertisement
Sign in to follow this  
guzumba

C# Question

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
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?

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
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#.

Share this post


Link to post
Share on other sites
Quote:
Original post by guzumba
Its a challenge in my book im learning.


Just curious, what book are you using?

Share this post


Link to post
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 < input; i++)
{
for (int j = 0; j < 10; j++)
{
rowArray[i, j] = i * j;
}
}
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!