The second one
01111
This is because a computer uses binary and only understands two digits which consit of 1 and 0
Answer / Explanation:
#include <iostream>
using namespace std;
int main()
{
int userNum = 0;
userNum = 20;
cout << userNum << " ";
while (userNum > 1)
{
userNum = userNum/2;
cout << userNum << " ";
}
cout << endl;
return 0;
}
However, we should note that the above codes divides properly but when it gets to 0, it will always give output as 0 instead of terminating the program.
Hence to make it terminate, we include:
while (userNum > 1)
{
cout << userNum << " ";
userNum = userNum/2;
}
The above code alternatively should be replaced with int userNum = 0; .
Also, for the sake of industry best standard and the general principle, we can say:
The general principle is:
while ( <conditional> )
{
// Use the data
// Change the data as the last operation in the loop.
}
A for loop provides natural placeholders for these.
for ( <initialize data>; <conditional>; <update data for next iteration> )
{
// Use the data
}
If you were to switch to using a for loop, which I recommend, your code would be:
for ( userNum = 20; userNum > 0; userNum /= 2 )
{
cout << userNum << " ";
Answer:
Configure Windows Firewall on the remote computer.
Explanation:
Answer:
Short-circuit evaluation is performed with the not operator.
i = 1
while i < 10001:
total = 0
x = 1
while x < i:
if i % x == 0:
total += x
x+=1
if total == i:
print(str(i)+" is a perfect number")
i += 1
When you run this code, you'll see that 6, 28, 496, and 8128 are all perfect numbers.