Week 8 Tasks

Functions & Recursion

Task 36

Write a program in C to check a given number is even or odd using the functions.

Task 37 (Experiment 15)

Write a program in C to print all the prime numbers between two numbers entered by the user using functions.

Task 38

WAP to find area of a circle and a hexagon and also find which shape has a larger area using functions.

$$ Area \ of \ Circle = \pi r^2 $$

$$ Area \ of \ Hexagon = \frac{3 \sqrt{3}}{2} a^2 $$

Task 39 (Experiment 16)

Write a program in C to find the Factorial of a number using recursion

$ 7! = 7 * 6 * 5 * 4 * 3 * 2 * 1 = 5040 $

Task 40

Write a program in C to Print Fibonacci Series using recursion

Fibonacci Series is a sequence of numbers in which each number is the sum of the two preceding ones, starting from 0 and 1.

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...

Task 41

Write a program to print pascal triangle using recursion function.

HINT #1

Each number is the numbers directly above it added together.

HINT #2

The formula for working out the value at any place in Pascal's triangle is $ \binom{n}{r} = nCr = \frac{n!}{r!(n-r)!} $

Where n is the row number and r is the column number.