99乘法表
var a = 1; for (int i = 1; i < 10; i++) { if (i == a) { Console.WriteLine(a + "×" + i + "=" + (a * i) + " "); } else { Console.Write(a + "×" + i + "=" + (a * i) + " "); } if (i > a) { for (int j = 2; j < i+1; j++) { Console.Write(j + "×" + i + "=" + (j * i) + " "); } Console.WriteLine(""); } }
自己半夜无聊写的,有更好的,可以推荐,谢谢
--优化代码:
for (int i = 1; i < 10; i++) { for (int j = 1; j <= i; j++) { Console.Write($"{j}×{i}={i*j} "); } Console.WriteLine(""); }