15 lines
199 B
C++
15 lines
199 B
C++
|
#include <iostream>
|
||
|
|
||
|
int sum(int n)
|
||
|
{
|
||
|
return (n != 0)
|
||
|
? n + sum(n - 1)
|
||
|
: n;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
int n = 5;
|
||
|
std::cout << "For n = " << n << " sum is " << sum(n) << '\n';
|
||
|
}
|