Pascal's triangle: Difference between revisions
Content added Content deleted
(→{{header|Perl 6}}: edit for style, remove superstitious parens) |
m (→{{header|C sharp|C#}}: Cleaned up indentation and formatting) |
||
Line 296: | Line 296: | ||
<lang csharp>using System; |
<lang csharp>using System; |
||
namespace RosettaCode |
namespace RosettaCode { |
||
{ |
|||
class PascalsTriangle { |
class PascalsTriangle { |
||
⚫ | |||
public static void CreateTriangle(int n) { |
|||
if (n > 0) { |
|||
for (int i = 0; i < n; i++) { |
|||
int c = 1; |
|||
Console.Write(" ".PadLeft(2 * (n - 1 - i))); |
|||
for (int k = 0; k <= i; k++) { |
|||
for (int k = 0; k <= i; k++) |
|||
{ |
|||
Console.Write("{0}", c.ToString().PadLeft(3)); |
Console.Write("{0}", c.ToString().PadLeft(3)); |
||
c = c * (i - k) / (k + 1); |
c = c * (i - k) / (k + 1); |
||
} |
|||
Console.WriteLine(); |
Console.WriteLine(); |
||
} |
|||
} |
|||
} |
|||
public static void Main() { |
|||
⚫ | |||
} |
} |
||
} |
} |