/* Use recursive algorithm */
#include <stdio.h>
void B (int n)//define function
{
if (n! = 0)
{
printf ("%d", n%2);
B (N/2);
}
}
int main ()
{
int n;
printf ("Input number:");
scanf ("%d", &n);
printf ("Output binary:");
B (n); Prints the binary number in the B () function
return 0;
}
/* Define an array and use Do{}while () to assign values */
#include <stdio.h>
int main ()
{
int A;
Char s[20];
int i = 0, rem;
printf ("Input number:");
scanf ("%d", &a);
Do
{
rem = a% 2;
A = A/2;
S[i] = REM;
i++;
} while (A! = 0);
printf ("Output binary:");
while (i > 0)
printf ("%d", s[--i]);//
return 0;
}
/* The code can implement a fixed output number */
#include <stdio.h>
#define N 32//fixed number of digits
int main ()
{
int Arr[n] = {0};//The array is initialized to 0 (the output 0 is filled when the number of bits is not satisfied)
int i;
int n;
printf ("Input number:");
scanf ("%d", &n);
for (i = N-1; I >=0; i--)//array from backward to forward assignment
{
Arr[i] = n% 2;
n = N/2;
}
printf ("Output binary:");
for (i = 0; I <= N-1; i++)
{
printf ("%d", arr[i]);
}
return 0;
}
C language converts decimal numbers to binary (recursive, specified number of digits)