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

Write a recursive function program to find the nth element in the following arit

ID: 3902725 • Letter: W

Question

Write a recursive function program to find the nth element in the following arithmetic numerical sequence: 3, 11, 27, 59, 123, Hint: You first have to figure out what is the recursive pattern. You also have to identify the base case. If you cannot write out the program in the space provided below, then print out the program on a separate sheet of paper and attach that to this homework. Please do not use more than 1 page, one sided. Some correct example outputs would look like this (there is no repeating loop-these are 2 separate runs): Which element of the sequence would you like to know? Element number 4 in the sequence is 59 Which element of the sequence would you like to know? Element number 7 in the sequence is 507

Explanation / Answer

program:--

#include<stdio.h>
#include<math.h>   //for pow function

int series(int n)   //recursive function for series
{
   int result;
   if(n==1)   //base condition
       return result=3;   //if n==1 result = 3
   else
       return result=series(n-1)+pow(2,n+1);   //else use recursion for 2nd term onwords
}

int main()   //main function
{
   int result,n;
   printf(" which element of the sequence would you like to know? "); //ask the user to enter n value
   scanf("%d",&n);   //read n
   result=series(n);   //call function with n
   printf("Element number %d in sequence is %d.",n,result);   //print result
   return 0;
}

output:--

1

which element of the sequence would you like to know?
4
Element number 4 in sequence is 59.

Process exited normally.
Press any key to continue . . .


2

which element of the sequence would you like to know?
7
Element number 7 in sequence is 507.

Process exited normally.
Press any key to continue . . .

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote