Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Could someone help me with this c++ assignment? For this assignment, you will wr

ID: 3669105 • Letter: C

Question

Could someone help me with this c++ assignment?

For this assignment, you will write two functions.

Function 1:

Write a function that accepts an integer argument and returns the sum of all the integers from 1 up to the number passed as an argument. For example, if 50 is passed as an argument, the function will return the sum of 1, 2, 3, 4, ... 50. Use recursion to calculate the sum. Demonstrate the function in a program.

Function 2:

Write a recursive function that accepts a string object as its argument and prints the string in reverse order. Demonstrate the function in a driver program.


A sample run:

Explanation / Answer

Multiple Questions : Answering 1st .

#include <iostream>
using namespace std;

int sum(int n){
    if(n==1)
        return 1;
    else
        return n+sum(n-1);
}
int main(){
    int n;
    cout<<"Enter n";
    cin>>n;
    cout<<" Sum= " <<sum(n);
   return 0;
}


----------------------

output:

Enter n 10
Sum= 55