0% found this document useful (0 votes)
11 views4 pages

Abdurahman Lab 5

Uploaded by

abdulwhy99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Abdurahman Lab 5

Uploaded by

abdulwhy99
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CS-201L

Data Structures and


Algorithms
Lab 05

C++ Programming Tasks with Pointers

Name: abdurahman
Roll no 21
Semester: 3rd

Presentation/Procedure Code Comments Response Total


& Conclusion
Lab Tasks

1. Write a recursive function in C++ to find the factorial of a number provided by

the user.

Procedure:

• The base case is when n is 0 or 1, returning 1.

• The recursive case multiplies n by the factorial of n - 1.

2. Write a simple function to print the Fibonacci series (0, 1, 1, 2, 3, 5, 8, 13, 21,

34, ...). The series should end before 50.

Procedure:

• Start with a = 0 and b = 1.

• Print a and update a and b until a exceeds 50.


3. Write a recursive function to print the Fibonacci series (0, 1, 1, 2, 3, 5, 8, 13,

21, 34, ...). The series should end before 50.

Procedure:

• The function prints n and recursively calls itself with the next Fibonacci pair (m, n +
m).

4. Write a program to solve the problem of Tower of Hanoi using recursive

function.

Procedure:

• For n = 1, move the disk from the source to the target.

• Otherwise, move n-1 disks recursively to the auxiliary peg, move the largest disk,
and then move the n-1 disks to the target peg
Conclusion:

I have implemented recursive and non-recursive solutions for calculating the factorial of a
number, printing the Fibonacci series, and solving the Tower of Hanoi problem. These tasks
helped me understand of recursion and iterative processes

You might also like