write a program that takes in a positive integer as input, and output a string of 1's and 0's representing the integer in binary. for an integer x; the algothm is as long as x is greater than 0 output x % (remainder is either 0 or 1 . x=x/2 in coral language

Respuesta :

Answer: Provided in the explanation section

Explanation:

The full questions says:

write a program that takes in a positive integer as input, and output a string of 1's and 0's representing the integer in binary. for an integer x; the algothm is as long as x is greater than 0 output x % (remainder is either 0 or 1 . x=x/2 in coral language. Note: The above algorithm outputs the 0's and 1's in reverse order.

Ex: If the input is:

6

the output is:

011

CODE:

#include <stdio.h>

int main() {

   int n;

   scanf("%d", &n);

   while (n > 0) {

       printf("%d", n % 2);

       n /= 2;

   }

   printf("\n");

   return 0;

}

2

#include <stdio.h>

int main() {

   int n;

   scanf("%d", &n);

   while (n > 0) {

       printf("%d", n % 2);

       n /= 2;

   }

   return 0;

}

cheers i hope this helped !!

ACCESS MORE