for语句之打印三角形问题
生活随笔
收集整理的這篇文章主要介紹了
for语句之打印三角形问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1.左下角直角三角形
Console.Write("請輸入要打印幾行:");int a = Convert.ToInt32(Console.ReadLine());for (int i = 1; i <= a; i++){for (int j = 1; j <= i; j++){Console.Write("☆");}Console.WriteLine();}2.左上角直角三角形
Console.Write("請輸入要打印幾行:");int a = Convert.ToInt32(Console.ReadLine());for (int i = 1; i <= a; i++){for (int j = a - i; j >= 0; j--){Console.Write("☆");}Console.WriteLine();}3.右下角直角三角形
Console.Write("請輸入要打印幾行:");int a = Convert.ToInt32(Console.ReadLine());for (int i = 0; i < a; i++){for (int j = 1; j <= a - (i + 1); j++){Console.Write(" ");}for (int k = 1; k <= i + 1; k++){Console.Write("☆");}Console.WriteLine();}4.菱形
Console.Write("請輸入要打印幾行:");int a = Convert.ToInt32(Console.ReadLine());for (int i = 1; i <= a; i++){for (int k = 1; k <= a-i; k++){Console.Write(" ");}for (int x = 1; x <= i*2-1; x++){Console.Write("☆");}Console.WriteLine();}for (int j = 1; j < a; j++){for (int k2 = 1; k2 <= j; k2++){Console.Write(" ");}for (int x2 = 1; x2 <= (a-j)*2-1; x2++){Console.Write("★");}Console.WriteLine();}?
?
轉載于:https://www.cnblogs.com/franky2015/p/4631609.html
總結
以上是生活随笔為你收集整理的for语句之打印三角形问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: touch命令
- 下一篇: 用SignalR 2.0开发客服系统[系