Sunday, January 21, 2018

[Bioinformatics 101] 007. Function Method



Hello! This is Kenneth J Han!

In this post, we are going to look at function (or method).




007. Function Method

Problem

Create a function (or a method) called Factorial.
The Factorial has one integer parameter "num" and returns factorial value of "num".
Calculate the value of 3 factorial, 4 factorial and 5 factorial.

Pseudocode

Factorial(num)
    result ← 1
    WHILE num > 0
        result ← result * num
        num ← num - 1
    RETURN result

result3 ← Factorial(3)
result4 ← Factorial(4)
result5 ← Factorial(5)

PRINT result3, result4, result5

Answer

6  24  120


If you have difficulties solving problem, visit the links below!
Your source code is on ready to serve!

Python source code answer on Github
Java source code answer on Github








See you on next post!

[Bioinformatics 101] 006. while loop



Hello! This is Kenneth J Han!

In this post, we are going to look at while loop.




006. WHILE Loop

Problem

Using WHILE Loop, calculate 5! (factorial) .

Pseudocode

num ← 5
result ← 1

WHILE num > 0
    result ← result * num
    num ← num - 1

PRINT result

Answer

120


If you have difficulties solving problem, visit the links below!
Your source code is on ready to serve!

Python source code answer on Github
Java source code answer on Github








See you on next post!

[Bioinformatics 101] 005. for statement



Hello! This is Kenneth J Han!

In this post, we are going to look at for statement.




005. FOR Statement

Problem

Sum all integers from 1 to 10.

Pseudocode

sum ← 0

FOR i ← 1 TO 10
    sum ← sum + i
PRINT sum

Answer

55


If you have difficulties solving problem, visit the links below!
Your source code is on ready to serve!

Python source code answer on Github
Java source code answer on Github








See you on next post!