您帮我看下这个程序吧:输出n阶杨辉三角。n由用户输入且不大于13。是等腰三角形的杨辉三角!我的程序如下
usingSystem;usingSystem.Collections.Generic;usingSystem.Text;namespaceproj4_15{classP...
using System;
using System.Collections.Generic;
using System.Text;
namespace proj4_15
{
class Program
{
static void Main(string[] args)
{
int n, i, j;
Console.WriteLine("请输入n的值:");
n = int.Parse(Console.ReadLine());
int[,] a=new int[n,n];
if (n > 13)
Console.WriteLine("请输入不大于13的整数!");
else
for (i = 0; i<n; i++)
for (j = 0; j<i; j++)
{
if (j == 0 || i == j)
a[i, j] = 1;
else
a[i, j] = a[i - 1, j - 1] + a[i - 1, j];
}
for( i = 0;i < n;i++)
for(j = 0;j <= i;j++)
Console.Write("{0,-2}",a[i,j]);
}
}
} 展开
using System.Collections.Generic;
using System.Text;
namespace proj4_15
{
class Program
{
static void Main(string[] args)
{
int n, i, j;
Console.WriteLine("请输入n的值:");
n = int.Parse(Console.ReadLine());
int[,] a=new int[n,n];
if (n > 13)
Console.WriteLine("请输入不大于13的整数!");
else
for (i = 0; i<n; i++)
for (j = 0; j<i; j++)
{
if (j == 0 || i == j)
a[i, j] = 1;
else
a[i, j] = a[i - 1, j - 1] + a[i - 1, j];
}
for( i = 0;i < n;i++)
for(j = 0;j <= i;j++)
Console.Write("{0,-2}",a[i,j]);
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询