
要打印 n 的 m 倍数,首先设置 m 和 n 的值 -
int n = 6, m = 1;
现在循环遍历 m 的值,递增它并在每次迭代时乘以 n -
while (m <= 5) {
// multiply n*m
m++;
}
让我们看完整的代码 −
现场演示
using System;
public class Demo {
public static void Main() {
int n = 6, m = 1;
while (m <= 5) {
Console.WriteLine(" {0} ", n * m);
m++;
}
}
}
6 12 18 24 30
以上就是在 C# 中打印 n 的前 m 倍数的详细内容,更多请关注php中文网其它相关文章!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号