C#控制台画图形
static void Main(string[] args) { //九九乘法 Console.WriteLine("九九乘法口诀"); for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { Console.Write(string.Format("{0}*{1}={2}\t", i, j, i * j)); } Console.WriteLine(); } //输入矩形 Console.WriteLine("矩形"); for (int i = 0; i < 3; i++) { //除了第一行和最后一行其余中间要空 for (int j = 0; j < 5; j++) { if (i > 0 && i != 2) { if (j > 0 && j != 4) { Console.Write(" "); } else { Console.Write("*"); } } else { Console.Write("*"); } } Console.WriteLine(); } //画一个等边三角形 Console.WriteLine("等边三角形"); int width = 5; for (int i = 1; i <= 5; i++) { for (int k = 1; k <= 5 - i; k++) { Console.Write(" "); } for (int j = 1; j <= i; j++) { Console.Write(" "); Console.Write("*"); } Console.WriteLine(); } //直角三角形 Console.WriteLine("直角三角形"); for (int i = 0; i < 5; i++) { for (int j = 0; j < i; j++) { Console.Write("*"); } Console.WriteLine(); } Console.ReadKey(); }
Console.WriteLine("1-2+3-4...100结果"); int sumO = 0; int sumJ = 0; for (int i = 0; i < 100; i++) { //索引0正好为奇数,奇数正,偶数负 if(i % 2 == 0) { sumO += i; } else { sumJ += -i; } } Console.WriteLine(string.Format("{0}",sumJ+sumO));
请大家指点不足,提出建议,共同分享学习.