Перевести программу с языка C# на C++:
using System;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
var m = 5;
var k = 8;
var result = Sum(m) + Sum(2 * k);
Console.WriteLine(result);
Console.ReadKey();
}
static int Sum(int n, int a = 0)
{
if (n-- == 0) return a;
return Sum(n, 1 + a + n);
}
}
}
Answers & Comments
#include <iostream>
static int Sum(int n, int a = 0) {
if(!n--)
return a;
return Sum(n, 1 + a + n);
}
signed main() {
int m = 5, k = 8;
int res = Sum(m) + Sum(2 * k);
std::cout << res << std::endl;
return 0;
}
{
if (n == 0)
{
n -= 1;
return a;
}
return a;
return Sum(n, 1 + a + n);
}
if (n == 0)
return a;
n = n - 1;
return Sum(n, 1 + a + n);
}