mirror of
https://github.com/foxsen/archbase.git
synced 2026-04-13 17:50:22 +08:00
initial import to public repository
This commit is contained in:
36
materials/chapter2/loop.c
Normal file
36
materials/chapter2/loop.c
Normal file
@@ -0,0 +1,36 @@
|
||||
int test_for(int a) {
|
||||
int sum = 0;
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < a; i++) {
|
||||
sum += i;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
int test_while(int a) {
|
||||
int sum = 0;
|
||||
int i = 0;
|
||||
|
||||
while (i < a) {
|
||||
sum += i;
|
||||
i++;
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
int test_dowhile(int a) {
|
||||
int sum = 0;
|
||||
int i = 0;
|
||||
|
||||
do {
|
||||
sum += i;
|
||||
i++;
|
||||
} while (i < a);
|
||||
|
||||
return sum;
|
||||
}
|
||||
Reference in New Issue
Block a user