0% found this document useful (0 votes)
10 views

Lab Assignment

Uploaded by

webd892
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)
10 views

Lab Assignment

Uploaded by

webd892
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/ 3

Assignment

Submitted BY:
Name: Kazi Abir Hasan
ID: 0242310005101213
Section: 64_L
Department of CSE

Submitted To:
Md. Ferdouse Ahmed Foysal
Lecturer
Department of CSE

Course Name: Programming and Problem Solving Lab


Course Code: CSE114
Date of Submission: 15/06/2023
Q: Write the recursive code to find N th Fibonacci
number.

#include<stdio.h>

int fibonacci(int n) {
if (n <= 0)
return 0;
else if (n == 1)
return 1;
else
return fibonacci(n - 1) + fibonacci(n - 2);
}
int main() {
int n;
printf("Enter the value of n: ");
scanf("%d", &n);

int result = fibonacci(n);


printf("The %dth Fibonacci number is: %d\n", n, result);

return 0;
}
Answer 02:
Last two digit for roll are 1&3;
10 mod of the sum of last digits is (1+3)%10==5.
So considering 4 as ‘n’ in problem 1, the recursion tree is
given below:

fib(4)
/ \
fib(3) fib(2)
/ \ / \
fib(2) fib(1) fib(1) fib(0)
/ \
fib(1) fib(0)

You might also like