Pascal's Triangle

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Dec 2008
Posts: 17
Reputation: Egypt Pharaoh is an unknown quantity at this point 
Solved Threads: 0
Egypt Pharaoh Egypt Pharaoh is offline Offline
Newbie Poster

Pascal's Triangle

 
0
  #1
Dec 21st, 2008
Please I want to make Pascal's triangle in console application
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,955
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 282
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: Pascal's Triangle

 
0
  #2
Dec 21st, 2008
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Pascal's Triangle

 
0
  #3
Dec 21st, 2008
Best to work it all out on paper first
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 17
Reputation: Egypt Pharaoh is an unknown quantity at this point 
Solved Threads: 0
Egypt Pharaoh Egypt Pharaoh is offline Offline
Newbie Poster

Re: Pascal's Triangle

 
0
  #4
Dec 22nd, 2008
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));
}

}
}
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,955
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 282
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: Pascal's Triangle

 
0
  #5
Dec 22nd, 2008
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.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Pascal's Triangle

 
0
  #6
Dec 22nd, 2008
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.
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC