-
Notifications
You must be signed in to change notification settings - Fork 0
/
CITest.c
45 lines (41 loc) · 979 Bytes
/
CITest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* Interpreter test program #1.
This program demonstrates all the features of the interpreter
*/
int i, j; /* global Variables */
char ch;
main(){
int i, j; /* local variables */;
puts("Demo #1");
print_alpha();
do{
puts("Input a number (0 - exit): ");
i = getnum();
if (i < 0) {
puts("number needs to be positive, try again");
}else{
for (j = 0; j < i; j + 1) {
print(j);
puts(" Added is ");
print(soma(j));
puts("");
}
}
} while (i != 0);
}
/* sums the values between 0 and num. */
soma(int num){
int soma_corr;
soma_corr = 0;
while (num) {
soma_corr = soma_corr + num;
num = num - 1;
}
return soma_corr;
}
/* prints the alphabet. */
print_alpha(){
for (ch = 'A'; ch<='Z'; ch = ch + 1) {
putch(ch);
}
puts("");
}