Preview:
#include <iostream>
using namespace std;

//int x= 0;      or .....global variable
int fun(int n)
{
    static int x=0;       //local static variable
    if(n>0)
    {
        x++;
       return fun(n-1) +x;
    }
    return 0;
}
int main() 
{
    int r;
    r = fun(5);
    cout<<r;
    return 0;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter