Starting from:

$30

COMP1410-Lab 1 Solved

Objectives:

-  Practice designing/implementing algorithms

-  Practice use of functions

 

Pre-requisite(s):


Code and document the following functions using NON-RECURSIVE ITERATION only.

 

Test the functions by calling them from a simple interactive main() function using a menu, with different values used to select the choice of function. Overall, you should have one C program (call it Lab1.c) containing one main() function and 5 other functions, where the functions are called based on an interactive user menu:

 

1
Summation:   ∑𝑛𝑘=1𝑘=1+2+3+⋯+𝑛   

n 1; reject with error message otherwise

[Note that this sum is equal to n(n+1)/2.  DO NOT program the function – program the series.]
2
Factorial(0) = 1;

Factorial(n) = n * (n-1) * . . . * 2 * 1

Requirement: n = 0; reject with error message otherwise
3
Fibonacci(0) = 0;

Fibonacci(1) = 1;

Fibonacci(n) = Fibonacci(n-1) + Fibonacci(n-2);

Requirement: n = 0; reject with error message otherwise
4
gcd (x, y) = x, if y=0

gcd (x, y) = gcd (y, x MOD y), if y 0

Requirement: x and y both 0; reject with error message otherwise
5
Power(a,b) = 𝑎𝑏

Requirement:  a 0, b 0, b is an integer; reject with error message otherwise
 

How to document functions?

/*

Objective: Describe the function/its purpose briefly

Input: Describe the input parameters, or the assumptions/requirements for the function. Output: Describe the output of the function. (What does it return? What does it print, if anything?)

More products