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
If your TV was showing a flat black or blue screen, or had "snow", what steps would you take to fix it?
faust18 [17]

Answer:

Assuming that TV was working fine and it stopped working when you restart or after power shutdown. Flat Black or blue screen or snow are all seems to be having HDMI cable sync issues. It can be fixed based on the model of the TV and connectivity it is using.

I would suggest to start with very basic step and should go step by step unless we narrow down the problem.

  1. Turn off all the components, unplug the cables and plug them back by leaving HDMI cables intact. So this process will reset all the units and may help in renegotiation.
  2. Plug all the cables and Turn on the TV.  Plug all other components like sound receiver and source device and Turn on the power.  This may solve the problem.
  3. If issue still persist. Unplug and Plug back HDMI cables and surrounding components in HDMI path. It may solve the issue.
  4. If the issue still persists, then change the HDMI cable itself and try rebooting all components.
  5. If input is changed then it might have caused the issue. So identify the cable from the receiver to the TV.  figure out its input and change the TV input to that value and it will work.
  6. In some TV's if power reset happens, It may revert to TV mode then change the video input based on your TV model.
  7. If the receiver is connected to TV via Coax then change the channel as per TV guide.
  8. If the receiver and its component is using AV or HDMI then use TV remote to change the input source until correct feed is found.
  9. If issue still persist, check the cable with another TV and see if it works. If its not then cable is at fault.
  10. If the cable is fine then change the TV and try above steps.If it works then TV is at fault.

Explanation:

8 0
4 years ago
Which of the following journals is not aimed at the public as well as scientists?
svet-max [94.6K]
"Journal of the IEST" is not aimed at the public as well as scientists since it deals primarily with very specialized and esoteric studies, and uses language that most non-scientists wouldn't understand. 
7 0
3 years ago
Write Python code to save the data to a MongoDB collection:Import json module to parse JSON dataImport MongoClient from pymongo
Zigmanuir [339]

Answer:

Explanation:

The objective of this task is to compute a program that involves the usage of Python code to save the data to MongoDB and to query  the database.

Due to the error that occur which makes me to be unable to submit this answer, I've created a word document instead and the attached file can be found below.

Thanks!

Download docx
8 0
3 years ago
A method for selecting multiple lines of text is to _______. select one:
Aliun [14]
I would probably say B even though the other methods might work as well
5 0
3 years ago
If you must use a credit card while in college what are some ways you can keep from getting in credit card debt?
marin [14]

Answer:

Pay attention to what you buy and limit yourself to an amount of money everyday.

Explanation:

This is just a simple way from spending a lot and limits your everyday spendings when you actually leave an amount for yourself.

3 0
4 years ago
Other questions:
  • WordArt styles allow you to add ____.
    9·1 answer
  • Refer to the exhibit. A network administrator configures a named ACL on the router. Why is there no output displayed when the sh
    7·1 answer
  • An example of movement as a gameplay mechanic includes
    14·2 answers
  • This is not based on homework but I have a question. I am currently using a gtx 960 with a 6 core amd processor. Does anyone kno
    6·1 answer
  • Dots (or periods) in a Java statement are used to separate the names of the components that make up the statement.
    8·1 answer
  • I'm looking for the best free chat website to Answer computer and statistic question and answers
    10·2 answers
  • Can you shoot video on the Olympus E-410?
    12·2 answers
  • Which of the following is not a method of the history object?
    11·1 answer
  • Why is it a good practice to use functions in programming? Select the best answer.
    9·1 answer
  • HEEEEEEEEEEEEEEEEELLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLPPPPPPPPPPPPPPPPPPPPPPPPPPP
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!