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
Random.choice will choose a number between 1 and 100. True False​
DaniilM [7]

Answer: False.

Explanation: Random.choice can choose between any 2 numbers.

6 0
3 years ago
Which storage is faster than secondary storage​
kozerog [31]

Answer:

RAM provides much faster accessing speed to data than secondary memory. By loading software programs and required files into primary memory(RAM), computer can process data much more quickly. Secondary Memory is slower in data accessing. Typically primary memory is six times faster than the secondary memory.22-Aug-2019

5 0
3 years ago
Read 2 more answers
Rectangular box formed when each column meet​
Over [174]

Answer:

If this is a true or false I guess my answer is true?

Explanation:

3 0
3 years ago
Because collecting the adjustment data requires time, the adjusting entries are often a.estimated and recorded earlier than the
Yanka [14]

Answer:

b. entered later but dated as of the last day of the period.

Explanation:

Because collecting the adjustment data requires time, the adjusting entries are often entered later but dated as of the last day of the period.

6 0
3 years ago
Read 2 more answers
When the computer begins to run a program
Ne4ueva [31]

Answer:

1.the program is moved from secondary storage to memory.

Explanation:

Secondary storage media generally have greater storage capacity than RAM (random access memory), for this reason the data and program are stored there.

but ram memories are much faster, for example, a solid state disk (SSD) with SATA III connection can have read and write speeds of approximately 500 MB/s, while a DDR III RAM can have speeds between 12 and 18 GB/S, that is, more than 20 times faster.

 So that the flow of data at the time of running a program is optimal, the data from the secondary storage unit is copied to the RAM and this ensures that the speed at which the programs run is at least 20 times faster, and our processes run better.

7 0
3 years ago
Other questions:
  • What is a way to Procter your social security number and other sensitive information from identity theft
    9·1 answer
  • Which technology enables afloat forces to communicate more securely and to operate in a more dispersed manner?
    6·1 answer
  • To expand the interface within CengageNOWv2, you need to click on the:_______.
    15·1 answer
  • You have just purchased a motherboard that has an LGA 1156 socket for an Intel Pentium processor. What type of memory modules wi
    14·1 answer
  • Travis just got promoted to network administrator after the previous administrator left rather abruptly. There are three new hir
    14·1 answer
  • When looking at aggregated logs, you are seeing a large percentage of Windows hosts connecting to an Internet Protocol (IP) addr
    5·1 answer
  • "Bookings are to be stored in three separate
    7·1 answer
  • Describe accessibility in Windows 7 ​
    13·1 answer
  • Is iphone battery being draned if plugged into car charger when listening to podcasts
    6·1 answer
  • Which option is typically only used when utilizing self joins?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!