Fortune Telling Collection - Fortune-telling birth date - Decimal conversion command
Decimal conversion command
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 ");
}
- Related articles
- The omen of dreaming of a three-legged snake
- The fortune teller told me what is more practice _ what is more practice?
- Mr. Shuimo fortune-telling website
- 1979 65438+123, born at 6: 00 p.m. in the twelfth lunar month, male, with type B blood, seeking fortune telling.
- Dujiangyan Bajiao Temple. Cheated 1900. What about you?
- Fortune-telling miracle novels _ Free reading of fortune-telling miracle novels
- Pencil Sharpener Fortune _ What is a Pencil Sharpener?
- Marriage without divination
- Ask the fortune teller.
- Baoshan fortune-telling prodigy _ What are Baoshan fortune-telling prodigies?