main() { int a,b; float c,d; a = 15; b = a / 2; printf("%d\n",b); printf("%3d\n",b); printf("%03d\n",b); c = 15.3; d = c / 3; printf("%3.2f\n",d); }
7 7 007 5.10
#includemain() { int Fahrenheit; for (Fahrenheit = 0; Fahrenheit <= 300; Fahrenheit = Fahrenheit + 20) printf("%3d %06.3f\n", Fahrenheit, (5.0/9.0)*(Fahrenheit-32)); }
0 -17.778 20 -6.667 40 04.444 60 15.556 80 26.667 100 37.778 120 48.889 140 60.000 160 71.111 180 82.222 200 93.333 220 104.444 240 115.556 260 126.667 280 137.778 300 148.889
#includemain() { printf("The color: %s\n", "blue"); printf("First number: %d\n", 12345); printf("Second number: %04d\n", 25); printf("Third number: %i\n", 1234); printf("Float number: %3.2f\n", 3.14159); printf("Hexadecimal: %x\n", 255); printf("Octal: %o\n", 255); printf("Unsigned value: %u\n", 150); printf("Just print the percentage sign %%\n", 10); }
The color: blue First number: 12345 Second number: 0025 Third number: 1234 Float number: 3.14 Hexadecimal: ff Octal: 377 Unsigned value: 150 Just print the percentage sign %
#includemain() { printf(":%s:\n", "Hello, world!"); printf(":%15s:\n", "Hello, world!"); printf(":%.10s:\n", "Hello, world!"); printf(":%-10s:\n", "Hello, world!"); printf(":%-15s:\n", "Hello, world!"); printf(":%.15s:\n", "Hello, world!"); printf(":%15.10s:\n", "Hello, world!"); printf(":%-15.10s:\n", "Hello, world!"); }
:Hello, world!: : Hello, world!: :Hello, wor: :Hello, world!: :Hello, world! : :Hello, world!: : Hello, wor: :Hello, wor :