Respuesta :
If you print the binary digits just like that, they'll be in the wrong order (lsb to msb). Below program uses recursion to print the digits msb to lsb. Just for fun.
void printBits(unsigned int n)
{
if (n > 1) {
printBits(n >> 1);
}
printf((n & 1) ? "1" : "0");
}
int main()
{
unsigned int number;
printf("Enter an integer number: ");
scanf_s("%d", &number);
printBits(number);
}
void printBits(unsigned int n)
{
if (n > 1) {
printBits(n >> 1);
}
printf((n & 1) ? "1" : "0");
}
int main()
{
unsigned int number;
printf("Enter an integer number: ");
scanf_s("%d", &number);
printBits(number);
}
The program illustrates the use of loops or iterative statements.
Loops and iterations are used to perform repetitive operations.
The program in Python, where comments are used to explain each line is as follows:
#This gets input from the user
num = int(input("Number: "))
#This initializes binary to an empty string
binary = ""
#This iteration is repeated while num is greater than 0
while num > 0:
#This gets the binary numbers
binary += str(num % 2)
#This gets the remainder of num divided by 2
num //= 2
#This reverses the string, and prints the binary equivalent of the number
print(binary[::-1])
The program is implemented using a while loop.
Read more about similar programs at:
https://brainly.com/question/14770682