+ 1
In this statement -> printf("Pi = %3.2f \n", 3.14159); /* Pi = 3.14 */ %3.2, 3 indicate what?????
new_price = price + increase; printf("New price is %4.2f", new_price); /* Output: New price is 8.50 */ printf("Pi = %3.2f \n", 3.14159); /* Pi = 3.14 */ printf("Pi = %8.5f \n", 3.14159); /* Pi = 3.14159 */ printf("Pi = %-8.5f \n", 3.14159); /* Pi = 3.14159 */
1 Antwort
+ 5
The number prior to the period "." represents field width, if this number is negative the field will be left-aligned, otherwise it will be right-aligned. Just to be clear, field here is the respective value to print using said format specifier.
The number following the period "." represents how many digits are desired to be displayed for decimal points.
For further details refer to this reference:
http://www.cplusplus.com/reference/cstdio/printf/