gpt4 book ai didi

c# - 从单个 for 循环生成乘法表

转载 作者:太空宇宙 更新时间:2023-11-03 18:48:32 24 4
gpt4 key购买 nike

是否可以使用单个 for 循环生成乘法表(例如,从 1 到 9)?

最佳答案

是的,使用这样的东西...但是为什么不使用两个嵌套循环呢?

        for (int i = 0; i < 9 * 9; ++i)
{
int a = i / 9 + 1;
int b = i % 9 + 1;
Console.WriteLine("{0} * {1} = {2}", a, b, a * b);
}

关于c# - 从单个 for 循环生成乘法表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2119743/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com