Pseudocode Functions
Pseudocode Functions
read number
If (number = 5)
else if (number = 6)
else
read count
set i to 0
i = i + 1
write even
https://www.qacps.org/cms/lib02/MD01001006/Centricity/Domain/847/Pseudo_Code%20Practice_Proble ms.pdf
user-defined functions
programmers can define their own functions (procedures, sub-
routines)
syntax
If the function returns a value then the type of that value must be
specified in function type(return type).
local-definitions
- definitions of variables that are used in the function-
implementation only (no meaning outside function).
int main ()
{
int a = 1000, b = 1001, answer;
// calling a function
answer = highest(a, b);
1. if n is 0, return 1
end factorial
https://en.wikipedia.org/wiki/Recursion_(computer_science)
example: factorial
n is 4 = 4 * f3
= 4 * (3 * f2)
= 4 * (3 * (2 * f1))
= 4 * (3 * (2 * (1 * f0)))
= 4 * (3 * (2 * (1 * 1)))
= 4 * (3 * (2 * 1))
= 4 * (3 * 2)
= 4 * 6
= 24
example: factorial
#include <iostream>
using namespace std;
long factorial (long a){
if (a > 1)
return (a * factorial(a-1));
else
return 1;
}