Fortune Telling Collection - Fortune-telling birth date - Decimal conversion command

Decimal conversion command

1. Open visualC++6.0- File-New-File -c++ Source File.

2. Input preprocessing commands and main functions:

# include & ltstdio.h & gt/* I/O header file */

Voidmain()/* Empty type: main function */

3. Define the data types of variables and arrays, and enter a decimal:

intb[ 16],x,k,r,I; /* Define the data types of variables and arrays as integers */

Printf ("Enter a decimal:"); /* output text prompt */

scanf("%d ",& ampx); ? /* Enter decimal number */

k =- 1; /* Assign-1 to k*/

4. Convert decimal numbers into binary numbers by dividing R by the remainder:

Do/* Converts decimal numbers into binary numbers by looping */

{

r = x % 2; /* Calculate binary */

b[++ k]= r; /* Assign a value to the array */

x/= 2; /* Divide the original number by 2*/

} while(x & gt; = 1);

5. Output results:

for(I = k; I & gt=0; I-)/* Returns the backward count above */

printf("%d ",b[I]); /* Output results */

printf(" \ n ");

6. Complete source code:

# include & ltstdio.h & gt/* I/O header file */

Voidmain()/* Empty type: main function */

{

intb[ 16],x,k,r,I; /* Define the data types of variables and arrays as integers */

Printf ("Enter a decimal:"); /* output text prompt */

scanf("%d ",& ampx); ? /* Enter decimal number */

k =- 1; /* Assign-1 to k*/

Do/* Converts decimal numbers into binary numbers by looping */

{

r = x % 2; /* Calculate binary */

b[++ k]= r; /* Assign a value to the array */

x/= 2; /* Divide the original number by 2*/

} while(x & gt; = 1);

for(I = k; I & gt=0; I-)/* Returns the backward count above */

printf("%d ",b[I]); /* Output results */

printf(" \ n ");

}