20181220作業(yè)


作業(yè)1

打印直角三角形

  1. 需求說明
    (1) . 從控制臺輸入直角三角形的高度(行數(shù))
    (2) . 每行 * 的數(shù)目依次為1、3、5、7…


代碼

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp48
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請輸入直角三角形行數(shù):");
int i = Convert.ToInt32(Console.ReadLine());

        string a = "*";
        Console.WriteLine("*");
        for (int j=1; j < i;j++)
        {
            a = a + "**";
            Console.WriteLine("{0}", a);
         } 

        Console.ReadKey();
    }
}

}


效果


image.png


作業(yè)2

打印倒直角三角形

  1. 需求
    從控制臺輸入直角三角形的高度(行數(shù))
    每行*的數(shù)目從下至上依次為1、2、3、4…

    代碼

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

namespace ConsoleApp49
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請輸入直角三角形的行數(shù):");
int i =0;
int n = 0;
for (i = Convert.ToInt32(Console.ReadLine()); i > 0; i--)
{
for (n = i; n> 0; n--)
{
Console.Write("*");
}
Console.Write("\n");
}
Console.ReadKey();
}
}
}


效果


image.png


作業(yè)3

打印等腰三角形

  1. 需求
    從控制臺輸入等腰三角形的高度
    每行*的數(shù)目依次為1、3、5、7…


代碼

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp51
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("請輸入等腰三角形的行數(shù):");
int i= Convert.ToInt32(Console.ReadLine());
try
{
for (int j = 1; j< i + 1; j++)
{
for (int n =i-j;n> 0; n--)
{
Console.Write(" ");
}
for (int a= 0; a < 2 * j- 1; a++)
{
Console.Write("*");
}
Console.WriteLine("");
}
}
catch
{
Console.WriteLine("輸入有誤,請重新輸入!");
}
Console.ReadKey();
}
}
}


效果


image.png


作業(yè)4

利用二重循環(huán)實現(xiàn)九九乘法表

代碼

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

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i;
int j;
for (i = 1;i<= 9; i++)
{
for (j =1; j <i; j++)
{
Console.Write("{0}{1}={2} ",j,i,i * j);
}
Console.WriteLine("{0}
{1}={2} ",j,i,i * j);
} Console.ReadKey();
}
}
}


效果


image.png

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容