60 337
Assignments Done
98%
Successfully Done
In April 2018

# Answer to Question #13947 in C# for neil john

Question #13947
Create a program that solves for the sum of all positive integers starting from 1 until the number given by the user. Use a recursive fuction to address this problem. Assume that the user will always enter a positive number.

Example:

Enter number: 100
Sum of integers from 1 to 100 is 5050.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Solves_for_the_sum_of_all_positive_integers
{
class Program
{
static void Main(string[] args)
{
int number;
Console.Write(&quot;Enter number:&quot;);
Console.Write(&quot;Sum of integers from 1 to &quot; + number.ToString() + &quot; is &quot; +
Sum(number));
}
static int Sum(int number) {
if (number &gt; 0)
{
return number + Sum(number - 1);
}
else
{
return 1;
}
}
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!