initial import
[staff/goc4/2018bti7061.git] / c-2-controlStructures / examples / controlStatements / loops.c
1 #include <stdio.h>
2 #include <ctype.h>
3
4 main(){
5 puts("--------------------------");
6 puts("Examples with DO... WHILE");
7 int digit = 0;
8 do
9 printf("%d\n",digit++);
10 while(digit <= 9);
11
12
13 char line[80];
14 int i = 0, size=0;
15 /* Scan one line (until a \n is read) */
16 puts("Type a line (to be transformed in uppercase):");
17 scanf("%[^\n]",line);
18 do
19 ++size;
20 while(line[size]!=0);
21
22
23 do {
24 putchar(toupper(line[i]));
25 i++;
26 } while (i<size);
27 putchar('\n');
28
29
30 puts("--------------------------");
31 puts("Examples with FOR");
32
33 for(digit = 0; digit <=9; ++digit){
34 printf("%d\n",digit);
35 }
36
37
38 for(i=0;i<size;i++){
39 putchar(toupper(line[i]));
40 }
41 putchar('\n');
42
43
44 }