- ..clause 1..: Digit arrangement of integer
- ..clause 2..: Computational display
- ..clause 3..: Digit arrangement of real number
The function not to have explained yet is provided though it is printf function that has been frequently used up to now.
The digit number leaves printf to the following program up to now.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { int a = 10000,b = 500,c = 3; Printf ("A is %d. \n" a); Printf ("B is %d. \n" b); Printf ("C is %d. \n" c); return 0; }
The figure is displayed as it is as understood even if the result is seen.
A 100.
B 50.
C 3. [Desu].
Do as follows to arrange the digit number by the printf function.
Number d of % digitsPut and display the blank to become the digit number if the figure is put between output conversion finger fixed children.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { int a = 10000,b = 500,c = 3; Printf ("A is %5d. \n" a); Printf ("B is %5d. \n" b); Printf ("C is %5d. \n" c); return 0; }
It is put the blank according to the digit number and is legible though understands when the result is seen.
A 100.
B 50.
C 3. [Desu].
Therefore, whenever the expected maximum digit number is specified, the digit is arranged and displayed.
..-.. because the sign is handled as one digit when you display a minus value moreover
It specifies it one digit more greatly when there is a possibility of displaying the value of the minus.
In the printf function, the display that uses 0 often seen with the computer is possible.
Come to display to put 0 ahead of the digit number putting 0 instead of the blank.
The following program is an example of the change to put 0 on the head.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { int a = 10000,b = 500,c = 3; Printf ("A is %05d. \n" a); Printf ("B is %05d. \n" b); Printf ("C is %05d. \n" c); return 0; }
I must think that it is a display like the computer somehow.
A 100.
B 005.
C 000.
In the display of the real number value, the number of decimals can be specified with the entire digit number.
Number of the entire % digits. Number f of decimal digitsThe number of whole digits is that what should be noted here contains the digit number and the decimal point of the decimal.
The following program is an example of displaying the real number value by the digit specification.
The execution result of this program becomes as follows.#include <stdio.h> int main(void) { double pi = 3.14159; printf("%6.2f\n",pi); printf("123456\n"); return 0; }
The line below is the one having put it to make the digit number easy to see.
3.14
123456
Other various specification can be done.
Refer to an output conversion finger fixed child of the word and the sign for details.