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 startValue = int.Parse(Console.ReadLine());
while(startValue > 1)
{
startValue /= 2;
}
}
}
}
Can anyone please help me to solve it?