Add test code
This commit is contained in:
43
test/arith.w12
Normal file
43
test/arith.w12
Normal file
@ -0,0 +1,43 @@
|
||||
fn factorial(n: int) -> int {
|
||||
var result: int;
|
||||
|
||||
if n == 0 {
|
||||
result = 1;
|
||||
} else {
|
||||
result = n * factorial(n - 1);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
fn is_positive(n: int) -> bool {
|
||||
return n > 0;
|
||||
}
|
||||
|
||||
fn main() -> int {
|
||||
var a: int = 5;
|
||||
printf("a = %d\n", a);
|
||||
|
||||
var b: int = 3;
|
||||
printf("b = %d\n", b);
|
||||
|
||||
var c: int = (a + b) * 2 - 1;
|
||||
c += factorial(5);
|
||||
|
||||
printf("c = %d\n", c);
|
||||
|
||||
while c > 0 {
|
||||
printf("c = %d\n", c);
|
||||
|
||||
if c > 50 {
|
||||
printf("c is greater than 50\n");
|
||||
} else {
|
||||
printf("c is less than or equal to 50\n");
|
||||
}
|
||||
|
||||
c -= 16;
|
||||
}
|
||||
|
||||
printf("End result: %d\n", c);
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user