Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q2 in c-programming: MyLab and Mastering × V-Course Home x y D Homework-06-Sprin

ID: 3722689 • Letter: Q

Question

Q2 in c-programming:

MyLab and Mastering × V-Course Home x y D Homework-06-Spring-20 @ replit-Hw 6 Q1 xC C)ECS4013-18Spring 0 x C E ESPN The worldwid 1 file://home/chronos/u-098f0a422b1 94aa432f0e5b77b6868e769e8f3ab/Downloads/Homework-06-Spring-2018.pdf ComingSoon.net M &IMDb; Movies, TV a O YouTube. Movies Movie Trail a Amazon.comOnlin-Wells Fargo Perso R welcome to Face CapitalOne Credit C Homework-06-Spring-2018.pdf 23 Q2: (Iteration instead of Recursion) (33 points) Any recursive program can be written using iteration instead of recursion. In lecture, you were given a recursive example of the Fibonacci series. Write a non- recursive function fibonnaci(n) that calculates the nth Fibonacci number. Student design of prompts and responses. You can restrict your program calculate Fibonacci numbers less than or equal to 45 to avoid integer overflows. Again, you may NOT use recursion. Q3: (Recursive Exponentiation) (34 points) Write a recursive function power( base, exponent) that when invoked returns baseexponernt For example, power( 3,4) 3 3 3 3. Assume that exponent is an integer greater than or equal to 1. Hint: The recursion step would use the relationship baseeponent basebaseonent-1 and the terminating condition occurs when exponent is equal to 1 because base base +2 6:33

Explanation / Answer

#include <stdio.h>
int main() {
int n;
printf("Enter the number less than or equals 45 : ");
scanf("%d", &n);
if(n == 0)
{
printf("0 ");
}
else if(n <= 45)
{
int a=0, b=1, c;
for(int i=2; i<=n; i++)
{
c = a+b;
a = b;
b = c;
}
printf("%d-th fibonnaci number is : %d ", n, b);
}
else
printf("Invalid input ");
}