initial import
[staff/goc4/2018bti7061.git] / c-2-controlStructures / examples / inputsoutputs / outputs.c
1 #include <stdio.h>
2
3 main(){
4
5 puts("Tests of output of strings (printf)");
6
7 /* Example 1 Printf */
8 double d1 = 101.593039;
9 puts("Example 1 : printf()");
10
11 printf("%f %.2f %.0f %2.2f \n",d1,d1,d1,d1);
12
13 /* Output: 101.593039 101.59 102 101.59
14 */
15
16
17 /* Example 2 Printf */
18 char line[]="ABCDEFGHIJKLMNOP";
19 puts("Example 2 : printf()");
20
21 printf("%10s %15s %15.5s %.10s\n",line,line,line,line);
22 /* Output:
23 ABCDEFGHIJKLMNOP ABCDEFGHIJKLMNOP ABCDE ABCDEFGHIJ
24 */
25
26
27 /* Example 3 Printf */
28 puts("Example 3 : printf()");
29 int i1 = 1234;
30 double x = 12.0, y = -3.3;
31
32 printf(":%6d %7.0f %10.1e:\n",i1,x,y);
33 printf(":%-6d %-7.0f %-10.1e:\n",i1,x,y);
34 printf(":%+6d %+7.0f %+10.1e:\n",i1,x,y);
35 printf(":%-+6d %-+7.0f %-+10.1e:\n",i1,x,y);
36 printf(":%7.0f %#7.0f %7g %#7g:\n",x,x,y,y);
37 /* Output:
38 : 1234 12 -3.3e+00:
39 :1234 12 -3.3e+00 :
40 : +1234 +12 -3.3e+00:
41 :+1234 +12 -3.3e+00 :
42 : 12 12. -3.3 -3.30000:
43 */
44
45
46 }