test:增加 Demo9
This commit is contained in:
parent
3a2f2125a8
commit
e9c1160993
31
playground/Demo9/Main.snow
Normal file
31
playground/Demo9/Main.snow
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
module: Math
|
||||||
|
function: main
|
||||||
|
parameter:
|
||||||
|
return_type: int
|
||||||
|
body:
|
||||||
|
Math.factorial(6)
|
||||||
|
return 0
|
||||||
|
end body
|
||||||
|
end function
|
||||||
|
|
||||||
|
function: factorial
|
||||||
|
parameter:
|
||||||
|
declare n:int
|
||||||
|
return_type: int
|
||||||
|
body:
|
||||||
|
declare num1:int = 1
|
||||||
|
loop:
|
||||||
|
initializer:
|
||||||
|
declare counter:int = 1
|
||||||
|
condition:
|
||||||
|
counter <= n
|
||||||
|
update:
|
||||||
|
counter = counter + 1
|
||||||
|
body:
|
||||||
|
num1 = num1 * counter
|
||||||
|
end body
|
||||||
|
end loop
|
||||||
|
return num1
|
||||||
|
end body
|
||||||
|
end function
|
||||||
|
end module
|
||||||
Loading…
x
Reference in New Issue
Block a user