1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
AlekseyPX
3 years ago
14

Write a recursive function program to find the nth element in the following arithmetic numerical sequence: 3, 11, 27, 59, 123, .

..
Computers and Technology
1 answer:
olga2289 [7]3 years ago
8 0

following are the code in c++

#include<bits/stdc++.h>

using namespace std;

//fuction to find nth term of the sequence

int val(int n){

  if(n==1){

      return 3;

  }else{

      return val(n-1)+8*pow(2,n-2);

  }

}

// driver fuction

int main(){

  int n;

  cout << "Which element of the sequence would you like to know?\n";

cin >> n;

//checking for input less than 1

do{

   if(n<1)

   {

   cout<<"Please enter a  number greater than 0:"<<endl;

   cin>>n;

   }

}while(n<1);

//printing the output

cout<<n<<"th element of the sequence is: ";

cout << val(n);

}

Explanation:

in the given code, if user enter input less than 1 then it will again ask for the input greater than 0 . When the input is greater than 0,it calls the recursive function  with the parameter n .if the input is 1 then function will give 3 as output. And when input is greater than 1, the recursive function will return nth element of the given sequence.

output

which element of the sequence would you like to know?                                                                      

-1                                                                                                                          

Please enter a  number greater than 0:                                                                                      

0                                                                                                                          

Please enter a  number greater than 0:                                                                                      

5                                                                                                                          

5th element of the sequence is: 123

You might be interested in
Jackson builders is constructing new homes in the Parkway subdivision.The company needs the logic for an application that ncalls
lord [1]
<span>The calculatePrice() method can be written in C. It will use and return doubles (which allows for decimals). It will calculate the house price of $100K + $20K per bedroom and $30K per bathroom. Next it will take that price and append the sales percentage and return that value.
double calculatePrice(decimal numBedrooms, decimal numBathrooms, decimal salesPercentage)
{
decimal housePrice = 100000 + (20000 * numBedrooms) + (30000 * numBathrooms);
return housePrice + (housePrice * salesPercentage);
}</span>
8 0
4 years ago
how can you turn on a light switch and it not work, without turning off the power to the whole house?
vitfil [10]

Answer:

Go to the beaker box and turn off the power to that one room. Duh

Explanation:

6 0
3 years ago
Justify the need for branching and jump codes in the instruction set using real world scenarios
topjm [15]

Answer:

As in the real world, people using a program would provide different inputs, that would require different outputs. For example in a traffic light system, there could be a function that constantly checks for if the button is pressed. When the button is pressed the traffic light loop would branch out of its current running code in order to turn the lights to red, and allow the pedestrians to cross.

8 0
3 years ago
Overcoming the fundamental attribution error requires making an effort to shift an external attribution into an internal attribu
Irina-Kira [14]

The correct answer on Edgen is:

(B.) False

I just took the test and this is the right answer.

8 0
4 years ago
Read 2 more answers
Which one of following is an example of a formatted number using the Currency option?
scoundrel [369]
C.) $7,778.92 is an example of a formatted number using the Currency option.

$ - is a currency symbol of the United States Dollars
, - is a currency symbol that separates whole numbers into group of 3 digits.
. - is a currency symbol that separates the whole amount from the centavos amount
7 0
4 years ago
Other questions:
  • To protect your answers after completing an assignment, what should you do? close your browser window. let someone else start wo
    14·1 answer
  • in Google, how should you phrase your search if you want to exclude a certain word from your results(for example,"chocolate")?
    14·1 answer
  • What can be said about the equipment used by photographers during the Civil War?
    13·2 answers
  • Labor-augmenting technology causes which of the following?(i) The marginal productivity of labor increases.(ii) The marginal pro
    7·1 answer
  • Which of the following gadgets is best for making a soft-shell shape out of butter?
    15·2 answers
  • Match the command to the use. Test connectivity to a remote computer Test DNS lookup View packets in a transmission Display the
    14·1 answer
  • Write a java program to input the corresponding data to print the result of the following expression
    9·1 answer
  • When power is completely removed from your computer
    11·1 answer
  • Think about that the C, B and S parameters of a Cache. Think about what happens to compulsory, capacity, conflict misses, if onl
    7·1 answer
  • At which layer of the osi model would a logical address be added during encapsulation?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!