| | |
Pascal's Triangle
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2008
Posts: 17
Reputation:
Solved Threads: 0
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));
}
}
}
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));
}
}
}
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.
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
Make love, no war. Cave ab homine unius libri.
Danny
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
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.
![]() |
Similar Threads
- C++ codes for pascal triangle (C++)
- Help With Pascal's Triangle in C++ (C++)
- Custom pascal triangle ? (C)
- Need Help With Printing Pascal's Triangle In C (C)
Other Threads in the C# Forum
- Previous Thread: javascript in c#
- Next Thread: Problem with 2 forms
| Thread Tools | Search this Thread |
.net access ado.net algorithm alignment array barchart bitmap box broadcast buttons c# c#gridviewcolumn check checkbox client color combobox communication control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing elevated encryption enum event excel file focus forloop form format forms function gdi+ hospitalmanagementsystem httpwebrequest image index input install java label list listbox login mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox serialization server sleep socket sql statistics stream string stringformatting sun table text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf xml






