943,640 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2263
  • C# RSS
Dec 21st, 2008
0

Pascal's Triangle

Expand Post »
Please I want to make Pascal's triangle in console application
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Egypt Pharaoh is offline Offline
40 posts
since Dec 2008
Dec 21st, 2008
0

Re: Pascal's Triangle

That is a very noble and honorable plan you have there. What is the code you have so far? What are the difficulties you encounter?
Please let us know.
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is online now Online
3,736 posts
since Oct 2008
Dec 21st, 2008
0

Re: Pascal's Triangle

Best to work it all out on paper first
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 22nd, 2008
0

Re: Pascal's Triangle

I had the code but it wasn't in the center
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x;
Console.WriteLine("Enter the number of rows ");
int n = int.Parse(Console.ReadLine());
for (int i = 0; i < n; i++)
{
for (int j = 0; j <= i; j++)
{
x = combination(i, j);
if (j == i)
Console.WriteLine(x);
else
Console.Write(x);
}
}
}
static int factorial(int n)
{
if (n == 0)
return 1;
else
{
int fact = 1;
for (int i = 1; i <= n; i++)
fact *= i;
return fact;
}
}
static int combination(int n, int r)
{
return factorial(n) / (factorial(r) * factorial(n - r));
}

}
}
Reputation Points: 10
Solved Threads: 0
Light Poster
Egypt Pharaoh is offline Offline
40 posts
since Dec 2008
Dec 22nd, 2008
0

Re: Pascal's Triangle

So what is your problem ?(besides the fact that your code is not put between code tags! Select your code and click the button marked #)
Your code works fine as is. The only thing that's missing as last line in your main function is Console.ReadKey(); or Console.ReadLine();
You will enjoy the outcome of your work more if you do that.
Reputation Points: 2023
Solved Threads: 644
Senior Poster
ddanbe is online now Online
3,736 posts
since Oct 2008
Dec 22nd, 2008
0

Re: Pascal's Triangle

If its not centred, thats why I suggested you worked it out on paper first.. What you need to do before you do any code is work out how the logic helps you decide where you would start it if you were human.. Once you have it worked out, you can then explain it to a computer.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: javascript in c#
Next Thread in C# Forum Timeline: Problem with 2 forms





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC