Question

1) a. Write the C++ program that uses a recursive function to print the elements of...

1) a. Write the C++ program that uses a recursive function to print the elements of a list in reverse order.

b. Write the pseudocode for the program.

Homework Answers

Answer #1

CODE IN C++:

#include <iostream>

using namespace std;
void print(int arr[],int n){
if(n==0)
return;
cout<<arr[n-1]<<" ";
print(arr,n-1);
}
int main()
{
int n;
cout<<"Enter the size of the array:";
cin>>n;
int arr[n];
int i;
cout<<"Enter the elements of the array:"<<endl;
for(i=0;i<n;i++){
cin >> arr[i];
}
cout<<"Displaying the elements of the array in reverse order:"<<endl;
print(arr,n);
return 0;
}
OUTPUT:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a C program to print the elements of an array in reverse order using pointer.
Write a C program to print the elements of an array in reverse order using pointer.
1. Write a C++ program that implements the recursive function isMember as declared above. Pass an...
1. Write a C++ program that implements the recursive function isMember as declared above. Pass an array to the function by reference. Here are two sample runs of the program. The elements of the array are: 0 4 5 6 7 Enter the element you want to find: 6 Element is in the array Press any key to continue . . .
Write an Oz program (having an Oz recursive function/procedure) which takes in the input a list,...
Write an Oz program (having an Oz recursive function/procedure) which takes in the input a list, say L, and two positive integers, M and N. The function should return another list L’, which represents the sub-list of L containing all the elements from index M to index N in reverse order. For example, if the input list is [a 2 g 5 4 k] and M is 2 and N is 5, then the output list should be [4 5...
Write a recursive C++ program that find the duplicate elements in an array. Your program shouldn't...
Write a recursive C++ program that find the duplicate elements in an array. Your program shouldn't use any sorting or use any additional array.
Write a recursive function count_digits that counts all the digits in a string. Program: C
Write a recursive function count_digits that counts all the digits in a string. Program: C
In java 1. Write a recursive algorithm to add all the elements of an array of...
In java 1. Write a recursive algorithm to add all the elements of an array of n elements 2. Write a recursive algorithm to get the minimum element of an array of n elements 3. Write a recursive algorithm to add the corresponding elements of two arrays (A and B) of n elements. Store the results in a third array C. 4. Write a recursive algorithm to get the maximum element of a binary tree 5. Write a recursive algorithm...
Write a program in C that uses recursion to calculate and print the factorial of the...
Write a program in C that uses recursion to calculate and print the factorial of the positive integer value passed in or prints the line "Huh?" if no argument is passed or if the first argument passed is not a positive integer. If the value passed in exceeds 10, you can simply print "Overvalue".
Python: Lee has discovered what he thinks is a clever recursive strategy for printing the elements...
Python: Lee has discovered what he thinks is a clever recursive strategy for printing the elements in a sequence (string, tuple, or list). He reasons that he can get at the first element in a sequence using the 0 index, and he can obtain a sequence of the rest of the elements by slicing from index 1. This strategy is realized in a function that expects just the sequence as an argument. If the sequence is not empty, the first...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use...
C++ Write a recursive function that reverses the given input string. No loops allowed, only use recursive functions. Do not add more or change the parameters to the original function. Do not change the main program. I had asked this before but the solution I was given did not work. #include #include using namespace std; void reverse(string &str) { /*Code needed*/ } int main() {    string name = "sammy";    reverse(name);    cout << name << endl; //should display...
Must have proper indentation must use the function swap write a C++ program that uses function...
Must have proper indentation must use the function swap write a C++ program that uses function swap to enter three real value from the keyboard and outputs there in order from minimum to the maximum. For example 10,100,30 if were entered then the output would be 10,30,100. The program should use function get_data(a,b,c) and print_data(a,b,c)
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT