Question
Working in C, modify the algorithm created in the Topic 1 assignment Non-Linear Flow Chart to instead compute the nth term in the series by
Working in C, modify the algorithm created in the Topic 1 assignment "Non-Linear Flow Chart" to instead compute the nth term in the series by calling a recursive function. Note that the value of "n" will need to be an input argument, along with the two starting values of the series. Discuss the efficiency of this method versus the iterative logic that you wrote previously.
Previous Code:
//main.c
#include
#include
int main()
{
//declare a integer data type variales
int first;
int second;
int result=0;
//Set INT_MAX as max value
int max=INT_MAX;
printf("Enter first value :");
scanf("%d",&first);
printf("Enter second value :");
scanf("%d",&second);
printf("%d,",first);
printf("%d,",second);
//Add the two values and store sum in result variable
result=first+second;
/*Loop till result is less than max value*/
while(result<=20000)
{
//print result value
printf("%d,",result);
//Assign second value to first
first=second;
//Assign the result to second
second=result;
//Add two values and assign sum to result
result=first+second;
//Break the loop if result is less than 0
if(result<0)
break;
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started