
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

Use recursion to calculate the greatest common divisor of two numbers, a and b, using the following pseudocode:
gcd(a, b) if b is zero, return a else return gcd(b, a % b)
Implement the method with prototype int gcd(int a, int b) in a source file gcd.c and write a main method to input a and b and output gcd(a,b). The table below includes a few sample inputs and outputs.
a b gcd(a,b) 4 6 2 24 5 1 35 7 7
Write a recursive method int lucas(int n) to take an integer n and output the value of L(n), where the recursion is defined as:
L(n) =
2 if n = 0 1 if n = 1 L(n − 1) + L(n − 2) otherwise
The value L(n) is called the nth Lucas number, after some dead French guy.
Write your implementation in a file lucas.c including a main method that inputs a value n and outputs the value lucas(n).
The table below lists the first eleven values of L(n).
n 0 1 2 3 4 5 6 7 8 9 10 L(n) 2 1 3 4 7 11 18 29 47 76 123