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
OverLord2011 [107]
3 years ago
11

Write a recursive function to compute sum of first N integers starting with 1.

Computers and Technology
1 answer:
Citrus2011 [14]3 years ago
4 0

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// recursive function to find sum from 1 to n

int recur_Sum(int n)

{ // base condition

if (n <= 1)

 return n;

// recursive call

return n + recur_Sum(n - 1);

}

// main function

int main()

{

   // variables

   int n;

   cout<<"Enter a number:";

   // read the number

   cin>>n;

   // print the sum

   cout<<"Sum of first "<<n<<" integer from 1 to "<<n<<" is:"<<recur_Sum(n);

return 0;

}

Explanation:

Read a number from user and assign it to variable "n".Call function recur_Sum() with parameter "n".This function will recursively call itself and find the Sum of first n numbers from 1 to n.Then function will return the sum.

Output:

Enter a number:10

Sum of first 10 integer from 1 to 10 is:55

You might be interested in
Suggest three ways in which celebrating an occasion influences food choices?
Basile [38]

Celebrating influences food in more than 1 way
6 0
2 years ago
Read 2 more answers
WILL DO A BRIANLY! Use an algorithm to help the Python Turtle get to the finish line in 10 steps by using only the 3 commands be
Alexandra [31]

Answer:

3 3 2 1 1

Explanation:

8 0
3 years ago
How would you classify an employee who is punctual, has respect for oneself and others, and takes initiative?
TEA [102]
C. They seem to take care of themselves and others. Can socialize and adapt easily.
6 0
3 years ago
Read 2 more answers
Microsoft's ____ is one of the major web-based development environments.
finlep [7]
The answer is ".NET" (had to increase character count to let me post).
4 0
3 years ago
Your motherboard supports dual channeling and you currently have two slots populated with DIMMs; each module holds 2 GB. You wan
Olenka [21]
One 4-GB DIMM. Dont really have a explanation for it just comes from previous experience
6 0
3 years ago
Read 2 more answers
Other questions:
  • What determines how large the crystals in an igneous rock will be?
    15·2 answers
  • Give big-O estimate for the number of operations (multiplication or addition) used in the following algorithm segment (ignore co
    15·1 answer
  • Translate each statement into a logical expression. Then negate the expression by adding a negation operation to the beginning o
    15·1 answer
  • Write a program called DeliveryCharges for the package delivery service in Exercise 4. The program should again use an array tha
    9·1 answer
  • Edhesive unit 4 test answers
    15·1 answer
  • What was used to enhance silent films of the early 1900s
    15·1 answer
  • Algorithm to eat orange<br><br>​
    10·2 answers
  • I need some help-
    15·1 answer
  • What does the word collaborative mean?
    13·2 answers
  • A program similar to mtr, ____, is available as a command-line utility in Windows operating systems.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!