按照标题;我已经尝试了多种方法,似乎无法理解我出错的地方。我觉得这和我一样接近,但有些事情似乎仍然很混乱。有人可以帮我完成这个吗? (此当前代码始终输出0)。
澄清;我希望代码能够读取用户输入的数字,并计算出在达到1之前可以减半的次数。
Console.WriteLine("Please enter a number to find how many time it can be divided without becoming less than 1");
Int32 DiviNum = Int32.Parse(Console.ReadLine());
Int32 count = 0;
for (int i = 0; i > 1; i = i / 2)
{
count++;
}
Console.WriteLine("Number of times " + DiviNum + " is divisible by 2 is " + count);
提前致谢
答案 0 :(得分:0)
解决方案
Console.WriteLine("Please enter a number to find how many time it can be divided without becoming less than 1");
Int32 DiviNum = Int32.Parse(Console.ReadLine());
Int32 count = 0;
for (int i = DiviNum/2 ; i > 1; i = i / 2)
{
count++;
}
Console.WriteLine("Number of times " + DiviNum + " is divisible by 2 is " + count);