九九乘法表的四种三角形排布方式(for循环以及while循环的互换)
Posted kai-youngmaster
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了九九乘法表的四种三角形排布方式(for循环以及while循环的互换)相关的知识,希望对你有一定的参考价值。
#region
//右上
for (int i = 1; i <= 9; i++){
for (int j = 1; j <= 9; j++){
if (i > j){
Console.Write(" ");
} else{
Console.Write("{0}*{1}={2} ", i, j, i * j);
}
}
Console.Write("
");
}
Console.ReadKey();
//右下
for (int i = 1; i <= 9; i++){
for (int j = 1; j <= 9; j++){
if (i < 9 + 1 - j){
Console.Write(" ");
}else{
Console.Write("{0}*{1}={2} ", i, j, i * j);
}
}
Console.Write("
");
}
Console.ReadKey();
Console.Write("
上层结束
");
//左上
for (int i = 1; i <= 9; i++){
for (int j = i; j <= 9; j++)
{
if (i > j){
Console.Write(" ");
} else{
Console.Write("{0}*{1}={2} ", i, j, i * j);
}
}
Console.Write("
");
}
Console.ReadKey();
Console.Write("
");
//左下
for (int i = 1; i <= 9; i++){
for (int j = 1; j <= 9; j++){
if (i <j){
Console.Write(" ");
}else{
Console.Write("{0}*{1}={2} ", i, j, i * j);
}
}
Console.Write("
");
}
Console.ReadKey();
Console.Write("
");
//右上
for (int i = 1; i <= 9; i++){
for (int a = 1;a < i; a++){
Console.Write(" ");
}
for (int j = i; j <= 9; j++) {
Console.Write("{0}*{1}={2} ", i, j, i * j);
}
Console.Write("
");
}
Console.ReadKey();
Console.Write("
");
#endregion
附加运行结果:
以上是关于九九乘法表的四种三角形排布方式(for循环以及while循环的互换)的主要内容,如果未能解决你的问题,请参考以下文章