- //
- // Copyright (c) 2014软件技术1班
- // All rights reserved.
- // 作 者:A09
- // 完成日期:2014年 11 月 23 日
- // 版 本 号:v1.0
- //
- // 问题描述:创建一个数组按条件输出这个数组
- // 输入描述:一个数组
- // 程序输出:杨辉三角形
- //
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication117
{
class Program
{
static void Main(string[] args)
{
double[,] x = new double[11, 11];
for (int i = 0; i < x.GetLength(0); i++)
{
for (int j = 0; j < x.GetLength(1); j++)
{
if (j == i || j == 0)
x[i, j] = 1;
else if (i > 1 && j > 0)
x[i, j] = x[i - 1, j - 1] + x[i - 1, j];
}
}
for (int i = 0; i < x.GetLength(0); i++)
{
for (int j = 0; j < x.GetLength(1); j++)
{
if (x[i, j] != 0)
Console.Write(" {0}", x[i, j]);
else Console.Write(" ");
}
Console.WriteLine();
}
Console.Read();
}
}
}
总结:
1.通过本作业我学会了数组声明,遍历,输出知识。
2.解决了杨辉三角问题,增长了经验,收获了自信。
3.以后会继续努力。