用.NET二维数组 打印出杨辉三角

wzy198712 2009-05-30 05:18:17
杨辉三角,杨辉三角。用.NET二维数组 打印出杨辉三角,谢谢啊~~~~~~
...全文
223 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianxialiu 2009-05-30
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.Text;

namespace shanjiao
{
class Program
{
static void Main(string[] args)
{

int [][]a=new int[10][];
for (int i=1; i <a.Length; i++) //让数组坐标从1开始
{
a[i] = new int[i + 1];
a[i][1] = 1; //使第一列元素值为1
a[i][i] = 1; // 使对角线元素为1
}
for (int i = 3; i < a.Length; i++)
{
for (int j = 2; j <= i - 1; j++)
{
a[i][j] = a[i - 1][j - 1]+a[i - 1][j];
}
}
for (int i = 1; i <a.Length; i++)
{
for (int j = 1; j <= i; j++)
{
Console.Write("{0,4}", a[i][j]);
}
Console.WriteLine();
}
Console.ReadLine();

}
}
}
SQL77 2009-05-30
  • 打赏
  • 举报
回复
   static void Main(string[] args)
{

int a,b;
int [][] yan=new int [8][];
for(a=0;a<yan .Length ;a++)
{
yan [a]=new int [a+1];
yan[a][0] = 1;
yan[a][a] = 1;
}
for (a = 2; a < yan.Length; a++)
{
for (b = 1; b < yan[a].Length-1; b++)
{
yan[a][b] = yan[a - 1][b - 1] + yan[a - 1][b];
}
}
for(a=0;a<yan.Length ;a++)
{
for (b=0;b<yan[a].Length ;b++)
{
Console.Write("{0,5}", yan[a][b]);
}
Console.WriteLine ();
}
Console.Read();
}
wuyq11 2009-05-30
  • 打赏
  • 举报
回复
int r=int.Parse(Console.ReadLine());
int[,] a=new int[r+1,r+1];
int i=0;int j=0;
for(;i<r;i++)
{
j=0;
for(;j<=i;j++)
{
if(j==0||j==i)
{
a[i,j]=1;
}
else
{
a[i,j]=a[i-1,j-1]+a[i-1,j];
}
Console.Write("{0} \t",a[i,j]);
}
Console.WriteLine();
}
Console.Read();



const int M = 7;
int[][] yhsj = new int[M][];
int i, j;
for (i = 0; i < M; i++)
yhsj[i] = new int[i + 1];
for (i = 0; i < M; i++)
{
yhsj[i][0] = 1;
yhsj[i][i] = 1;
}
for (i = 2; i < M; i++)
for (j = 1; j < i; j++)
yhsj[i][j] = yhsj[i - 1][j - 1] + yhsj[i - 1][j];
for (i = 0; i < M; i++)
{
Console.WriteLine();
for (j = 0; j <= i; j++)
Console.Write("{0} ", yhsj[i][j]);
}
Console.Read();
  • 打赏
  • 举报
回复
明白其逻辑是关键
  • 打赏
  • 举报
回复
自己把格式改改
  • 打赏
  • 举报
回复
/*
* Created by SharpDevelop.
* User: qsmy
* Date: 2009-05-30
* Time: 19:07
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;

namespace yangFei
{
class Program
{
public static void Main(string[] args)
{
int c=1;
int i,m,n;
Console.Write("请输入i的值:");
i=Convert.ToInt32(Console.ReadLine());
for(m=0;m<=i;m++)
{
Console.Write(" "+c.ToString());
for(n=1;n<=m;n++)

{


c=c*(m-n+1)/n;
Console.Write(" {0}",c);

}
Console.WriteLine("");
}
Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);

}
}
}
liumj2001 2009-05-30
  • 打赏
  • 举报
回复
小学毕业。。。。。。。
十八道胡同 2009-05-30
  • 打赏
  • 举报
回复
2维数组我是用
List<List<int> >arr=new List<List<int> >()

这样来的
十八道胡同 2009-05-30
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 liumj2001 的回复:]
杨辉是谁?

学习帮顶。
[/Quote]

杨辉三角没学过?初中的知识吧
liumj2001 2009-05-30
  • 打赏
  • 举报
回复
杨辉是谁?

学习帮顶。
飞天鹰 2009-05-30
  • 打赏
  • 举报
回复
帮顶一下

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧