如何仅使用循环来划分两个用户输入并且不允许使用任何操作?

How can I divide two user inputs using only loops and using any operations is not allowed?

Console.Write("Input Value for A: ");

int a = int.Parse(Console.ReadLine());

Console.Write("Input Value for B: ");
int b = int.Parse(Console.ReadLine());

int acc = 0;
for (int i = a; a >= b; a--)
{
    acc += b;
}

Console.Write("The quotient is {0}", acc);
Console.ReadKey(true);

好吧,这是一个技巧问题,因此我立即反感它。解决方法如下:

var quotient = 0;   
for (var acc = b; acc <= a; acc += b, quotient += 1);
Console.Write($"The quotient of {a} divided by {b} is {quotient}");

诀窍在于您仍在使用操作,但作为循环本身中的一个步骤而不是作为循环体内的显式操作,这可能是练习的重点。

UPDATE:如果 ab 具有相同的符号,此代码仅提供准确的结果。