Skip to main content

Posts

Showing posts with the label summation program using recursive function

Sample C Program To Implement Recursive Algorithm Using Pointers.

ALGORITHM: STEP 1: Start the program. STEP 2: Declare the variable, *no, factorial, sum, p, i, and the function fact (int p), sum (int p), fib (int p). STEP 3: Read the value of no. STEP 4: Call the function fact (*no), sum (*no). STEP 5: Use for loop call the function fib (int p) and display the Fibonacci series & also display factorial & summation. STEP 6: Stop the program. FUNCTION FIB (int p) - FIBONACCI SERIES. STEP 1: Check whether the value of n is equal to '0' if so return '0'. STEP 2: Else check whether (p >= 1 && p <= 2), if so return the value '1'. STEP 3: Else return ( fib ( p – 1 ) + fib( p – 2 ) ). FUNCTION FACT (int p) - FACTORIAL OF A NUMBER. STEP 1: Check whether (p == 0), if so return '1' . STEP 2: Else return (p * fact( p – 1 ) ). FUNCTION SUM (int p) - SUMMATION OF A NUMBER. STEP 1: Check whether p == 0, if so return '0'. STEP 2: Else return (p + sum( p – 1 ) ). ...