问题及代码:
运行结果:
菱形星号图。
/*
*Copyright (c)2014,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:star.cpp
*作 者:单昕昕
*完成日期:2015年2月5日
*版 本 号:v1.0
*
*问题描述:输出一个星号图。
*程序输出:一个星号图。
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Test
{
class Program
{
static void Main()
{
int a, b, c;
for (a = 1; a <= 6; a++)
{
for (b = 5; b >= a; b--)
{
Console.Write(" ");
}
for (c = 1; c <= 2 * a - 1; c++)
{
Console.Write("*");
}
Console.Write("\n");
}
int i, k, h;
for (i = 1; i <= 6; i++)
{
for (k = 1; k <= i; k++)
{
Console.Write(" ");
}
for (h = 1; h <= 11 - 2 * i; h += 1)
{
Console.Write("*");
}
Console.Write("\n"); ;
}
Console.ReadLine();
}
}
}
运行结果:
菱形星号图。
学习心得:
用变量控制输出。