Hello, I’m working on this task:
Write a program that reads an integer from the console. The integer should be a power of two: 2, 4, 8, 16, 32, etc. Then your program should divide it by 2 and output every division result to the console, until it reaches number 1. Print out each result to a new line. Use a while loop. For example:
>16
8
4
2
1
Here is my code:
namespace WhileLoop
{
class InfiniteDividor
{
static void Main(string[] args)
{
int number = int.Parse(Console.ReadLine());
while(number > 1)
{
Console.WriteLine(number);
number = number / 2;
}
Console.WriteLine(number);
}
}
}
Can anyone please help me to solve it?