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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!