杨辉三角 等腰的c#代码

z33yh 2010-04-01 07:51:09
c#代码~~~
...全文
220 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
DuBarlow 2010-04-01
  • 打赏
  • 举报
回复
 ArrayList[]arr=new ArrayList[10];
for (int i = 0; i < 10; i++)
{
arr[i] = new ArrayList();
}
arr[0].Add(1);

for (int i = 1; i <= 9; i++)
{
for (int j = 0; j <= i; j++)
{
if (j == 0 || j == i)
arr[i].Add(arr[i - 1][0]);
else
arr[i].Add((int)arr[i-1][j-1]+(int)arr[i-1][j]);
}
}

for (int i = 0; i < 10;i++)
{
for (int j = 0; j < arr[i].Count; j++)
Console.Write("{0}\t",arr[i][j]);
Console.WriteLine();
}
Console.ReadKey();
wuyi8808 2010-04-01
  • 打赏
  • 举报
回复
这总可以了吧:
class Program
{
static void Main()
{
int n = 5;
int[,] a = new int[n,n];
for (int i = 0; i < n; i++)
{
a[i,0] = a[i,i] = 1;
System.Console.Write(new string(' ', n - i - 1));
System.Console.Write(a[i,0]);
for (int j = 1; j <= i; j++)
{
if (i > 0 && j < i) a[i,j] = a[i-1,j-1] + a[i-1,j];
System.Console.Write(" " + a[i,j]);
}
System.Console.WriteLine();
}
}
}
风消云散Fly 2010-04-01
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.Text;

namespace yanghui
{
class Program
{
static void Main(string[] args)
{
int i;
int [] yh=new int[8];
for(i=0;i<8;i++)
{
yh[i]=1;
for(int j=i-1;j>0;j--)
yh[j]=yh[j-1]+yh[j];
for(int k=8;k>=i;k--)
Console.Write(" ");
for(int j=0;j<=i;j++)
{
string s=yh[j].ToString();
if(s.Length==1)
Console.Write(yh[j]+" ");
else
Console.Write(yh[j]+" ");
}
Console.WriteLine();
}
}
}
}


lz给分吧
z33yh 2010-04-01
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 wuyi8808 的回复:]
C# code
System.Console.WriteLine(" 1");
System.Console.WriteLine(" 1 1");
System.Console.WriteLine(" 1 2 1");
System.Console.WriteLine(" 1 3 3 1");
System.Console.WriteLine("1 4 6 4 1");

……
[/Quote]

大哥 都叫你大哥了~~~典型 我要算法的~~~~就别糊弄小弟了~~我急要 不然就自己调试写了
Justin-Liu 2010-04-01
  • 打赏
  • 举报
回复
哈哈
wuyi8808 2010-04-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 z33yh 的回复:]
哥们别耍我啊~~~~愚人节啊
[/Quote]
那么3楼的应该符合LZ要求了吧?
wuyi8808 2010-04-01
  • 打赏
  • 举报
回复
System.Console.WriteLine("    1");
System.Console.WriteLine(" 1 1");
System.Console.WriteLine(" 1 2 1");
System.Console.WriteLine(" 1 3 3 1");
System.Console.WriteLine("1 4 6 4 1");
z33yh 2010-04-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyi8808 的回复:]
C# code
Sysetm.Console.WriteLine("杨辉三角");
[/Quote]

哥们别耍我啊~~~~愚人节啊
wuyi8808 2010-04-01
  • 打赏
  • 举报
回复
Sysetm.Console.WriteLine("杨辉三角");

110,538

社区成员

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

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

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