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
How does abstraction help us write programs
Misha Larkins [42]

Answer:

Abstraction refines concepts to their core values, stripping away ideas to the fundamentals of the abstract idea. It leaves the common details of an idea. Abstractions make it easier to understand code because it concentrates on core features/actions and not on the small details.

This is only to be used for studying purposes.

Hope it helps!

4 0
3 years ago
What are the three fundamental elements of an effective security program for information systems?
marishachu [46]
<span>the three fundamental elements of an effective security program for information systems are Identification, Authentication and Authorization.The access control creates the user and assigns the rights to resources and authorization is giving permissions to the users to access the resources.The user who wants to enter the system should have a valid data t enter the system like password, fingerprint or any other type of recognition.</span>
4 0
3 years ago
Read 2 more answers
A fast way to add up a column of numbers is to click in the cell below the numbers and then: Click Subtotals on the Data menu. V
Art [367]

Answer:

Click the AutoSum button on the Standard toolbar, then press ENTER

Explanation:

Excel offers a range of options to perform various mathematical operations. When numeric values are being inputted into cells, either columns or rows, the AutoSum function which is located in the home Taskbar allows for a very fast addition of the total values in the column or rows. Once the cell after the last cell value is selected, the AutoSum function is selected and the ENTER button is pressed, this will use the sum function of excel to quickly provide the total sum of all the values in the column.

3 0
3 years ago
Read 2 more answers
Which image property helps to create distinction between the highlights and shadows of an object?
Nutka1998 [239]
I know filters, so I know it is Saturation.
6 0
2 years ago
Read 2 more answers
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
2 years ago
Other questions:
  • Why is color theory important
    6·2 answers
  • What is a Better Computer?<br> A. Alien<br> B. Microsoft<br> C. Windows<br> D. Apple
    11·2 answers
  • This needs to be written in Java.
    11·1 answer
  • What piece of software tells the operating system how to use a specific hardware device? a. User interface b. System service c.
    14·1 answer
  • The arguments in a method call are often referred to as ____ . The variables in the method declaration that accept the values fr
    10·1 answer
  • (This is for photography segment exam btw)
    11·2 answers
  • A company is deploying NAFDs in its office to improve employee productivity when dealing with paperwork. Which of the following
    11·1 answer
  • A town government is designing a new bus system. The planners are deciding where to put the different bus stops. They want to pi
    6·2 answers
  • How to Calculate the area of a rectangle in python
    13·2 answers
  • Which of the following statement is correct ? A . potential difference is measured by ammeter . B . The unit of potential differ
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!