帮帮我 解决一个对于你们简单的问题急急急!!
using System;using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
public static void Main(string[] args)
{
int k=6;
int[][] a = new int[k][];
for (int i = 0; i < a.Length; i++)
a[i] = new int[i + 1];
for (int j = 0; j < a.Length; j++)
{
a[j][0] = 1;
a[j][a[j].Length - 1] = 1;
for (int m = 1; m < a[j].Length - 1; m++)
a[j][m] = a[j - 1][m - 1] + a[j - 1][m];
}
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < a[i].Length; j++)
Console.WriteLine("{0}\t",a[i][j]);
Console.Write("\n");
}
}
}
} 1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
我想要这种 输出格式的 应该怎么改进20
--------------------编程问答-------------------- 帮帮忙啊 大虾们!! --------------------编程问答--------------------
--------------------编程问答-------------------- Google 打印杨辉三角形 --------------------编程问答-------------------- namespace ConsoleApplication2
static void Main(string[] args)
{
int k = 6;
int[][] a = new int[k][];
for (int i = 0; i < a.Length; i++)
a[i] = new int[i + 1];
for (int j = 0; j < a.Length; j++)
{
a[j][0] = 1;
a[j][a[j].Length - 1] = 1;
for (int m = 1; m < a[j].Length - 1; m++)
a[j][m] = a[j - 1][m - 1] + a[j - 1][m];
}
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < a[i].Length; j++)
Console.Write("{0}\t", a[i][j]);
Console.WriteLine();
}
Console.ReadKey();
}
{
class Program
{
public static void Main(string[] args)
{
int x, y;
int[,] a = new int[7,7];
for (x = 0; x <= 6; x++)
{
for (y = 0; y <= x; y++)
{
if (x == y || y == 0)
a[x, y] = 1;
else
a[x, y] = a[x - 1, y - 1] + a[x - 1, y];
Console.Write(a[x, y] + " ");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
--------------------编程问答--------------------
+1 --------------------编程问答-------------------- 这个问题很囧啊,怪不得大家都说,算法是程序的灵魂呢! --------------------编程问答-------------------- 网上都有案例的啊··输出· --------------------编程问答-------------------- +1.
补充:.NET技术 , C#