[ create a new paste ] login | about

Link: http://codepad.org/5afOfcH1    [ raw code | output | fork ]

k06a - C++, pasted on Jan 26:
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>

int g(int n)
{
    return (n == 0) ? 0 : g(n-1)+n+n-1;
}

int main()
{
    std::cout << g(5) << std::endl;
    std::cout << g(14) << std::endl;
    std::cout << g(23) << std::endl;
}


Output:
1
2
3
25
196
529


Create a new paste based on this one


Comments: