C examples for Language Basics:printf
Conversion | Output Specification |
---|---|
%a | Floating-point number, hexadecimal digits and p-notation (C99/C11). |
%A | Floating-point number, hexadecimal digits and P-notation (C99/C11). |
%c | Single character. |
%d | Signed decimal integer. |
%e | Floating-point number, e-notation. |
%E | Floating-point number, e-notation. |
%f | Floating-point number, decimal notation. |
%g | Use %f or %e , depending on the value. The %e style is used if the exponent is less than -4 or greater than or equal to the precision. |
%G | Use %f or %E , depending on the value. The %E style is used if the exponent is less than -4 or greater than or equal to the precision. |
%i | Signed decimal integer (same as %d ). |
%o | Unsigned octal integer. |
%p | A pointer. |
%s | Character string. |
%u | Unsigned decimal integer. |
%x | Unsigned hexadecimal integer, using hex digits 0f . |
%X | Unsigned hexadecimal integer, using hex digits 0F . |
%% | Prints a percent sign. |
#include <stdio.h> #define PI 3.141593//from w ww . j a v a 2 s . c o m int main(void){ int number = 7; float pies = 12.75; int cost = 7800; printf("The %d contestants ate %f berry pies.\n", number, pies); printf("The value of pi is %f.\n", PI); printf("Farewell! thou art too dear for my possessing,\n"); printf("%c%d\n", '$', 2 * cost); return 0; }