0% found this document useful (0 votes)
39 views2 pages

Coding Cheat Sheet

The document contains definitions for 9 functions: 1. triangle - Prints a triangle of asterisks given a number n 2. square - Prints a square of X's given a number n 3. search - Searches for a number in a list and prints if found 4. invertedRTriangle - Prints an inverted right triangle of asterisks given a number n 5. factorial - Returns the factorial of a given number n 6. evened - Prints only the even indexed elements of a space separated list 7. parenthesis - Prints matching parentheses n times 8. invertedRTriangle - Prints an inverted right triangle of asterisks given a number n 9. factorial - Returns the factorial of

Uploaded by

Kirsten Mayuga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Coding Cheat Sheet

The document contains definitions for 9 functions: 1. triangle - Prints a triangle of asterisks given a number n 2. square - Prints a square of X's given a number n 3. search - Searches for a number in a list and prints if found 4. invertedRTriangle - Prints an inverted right triangle of asterisks given a number n 5. factorial - Returns the factorial of a given number n 6. evened - Prints only the even indexed elements of a space separated list 7. parenthesis - Prints matching parentheses n times 8. invertedRTriangle - Prints an inverted right triangle of asterisks given a number n 9. factorial - Returns the factorial of

Uploaded by

Kirsten Mayuga
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#1 #3 #8

function triangle n function square n function search n


put 1 into x put 1 into x put n into snumbers
repeat until x = n+1 repeat until x = n+1 split snumbers by comma
repeat for n-x times if x=1 or x=n then put 1 into x
put " " after field "label1" repeat for n times put the number of elements of snumbers into y
end repeat put "X" after field "label1" #firstrowlastrow repeat while x<=y
repeat for x*2-1 times end repeat if x=snumbers [x] then
put "*" after field "label1" put cr after field "label1" #linebreak put snumbers[x] & " " & cr after field "label1"
end repeat else #2ndrowonwards end if
put cr after field "label1" put "X" after field "label1" #startnextline put x + 1 into x
put x + 1 into x repeat for n-2 times #forthe+ end repeat
end repeat put "+" after field "label1" return empty
return empty end repeat end search
end triangle put "X" & cr after field "label1"
#fortheXafterthe+ #9
#2 end if function factorial n
function invertedRTriangle n put x + 1 into x if n = 0 then
put 1 into x end repeat return 1
repeat until x > n return empty else
if x=n then end square return factorial(n-1) * n
repeat for n times end if
put "*" after field "label1" #lastrow #7 end factorial
end repeat function evened n
else #1strowonwards put n into e #variable #10
repeat for n-x times split e by space function parenthesis n
put " " after field "label1" put 1 into x if n=0 then
end repeat return ""
repeat for x times else
put "*" after field "label1" #forthe*** put the number of elements of e into y repeat n times
end repeat repeat while x<=y put "(" before field "label1"
put cr after field "label1" if x mod 2 = 0 then put ")" after field "label1"
end if put e[x] & " " after field "label1" end repeat
put x + 1 into x end if end if
end repeat add 1 to x end parenthesis
return empty end repeat
end invertedRTriangle end evened

You might also like