Skip to content

Commit

Permalink
docs: add samples
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffswt committed May 2, 2021
1 parent 0135801 commit 9bf3023
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
22 changes: 22 additions & 0 deletions samples/fastpow.nh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# calculates a to the power of b
function fastpow a b as
let res = 1
let tmp = a
while > b 0 do
if == % b 2 1 then
let res = * res tmp
end if
let tmp = * tmp tmp
let b = / b 2
end while
return res
end function

function main as
let a = scan
let b = scan
let c = fastpow a b
print a b c
return 0
end function
23 changes: 23 additions & 0 deletions samples/max_four.nh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

function max_four a b c d as
if > b a then
let a = b
end if
if > c a then
let a = c
end if
if > d a then
let a = d
end if
return a
end function

function main as
let vara = scan
let varb = scan
let varc = scan
let vard = scan
let mx = max_four vara varb varc vard
print vara varb varc vard mx
return 0
end function

0 comments on commit 9bf3023

Please sign in to comment.