#include <stdio.h>intMain () {Doublex =256.141592654; intn = (int) x% +;//Integer Part while(n)//integer Partial output { intTEMP = n%Ten; N/=Ten; printf ("%d\n", temp); } inti =5; while(i>0)//Output 5 decimal places{x= x*Ten; printf ("%d\n",(int)% xTen);//forces a double to be converted to int, because the remainder (%) must be of type int,i--; } return 0;}
Attached: C language, how to output each digit? Https://zhidao.baidu.com/question/584309257492424645.html
One, the traditional method, through division and modulo, remove each bit, and output.
#include <stdio.h>voidOutputintN) { inta[Ten]; intL=0; /*loops get the value of each bit and coexist in array a. where L represents the number of bits that have been acquired. Since each acquisition is a single-digit n%10, there is an inverse of each single digit in array A. */ while(n) {a[l+ +] = n%Ten; N/=Ten; } //outputs each bit value in reverse order. while(--l>=0) printf ("%d", A[l]); }intMain () {intN; scanf ("%d", &n);//Enter an n value. Output (n);//output individual bits. return 0;}
Two, convert to a string, and then output the character string.
Because in the C language, there are many library functions, such as itoa, sprintf, etc., can be very convenient to convert an integer to a string, and the bit-wise output string Each byte value is very simple, so can be converted to a string, and then output the value of each bit.
#include <stdio.h>voidOutputintN) { Chara[ One]; inti; sprintf (A,"%d", n);//convert to a string. for(i =0; A[i]; i++)//iterates through a string. printf"%c", A[i]);//output individual bit values. }intMain () {intN; scanf ("%d", &n);//Enter an n value. Output (n);//output individual bits. return 0;}
C language extracts every bit of a double