Untitled

mail@pastecode.io avatar
unknown
c_cpp
16 days ago
310 B
0
Indexable
Never
#include <iostream>
#include <string>


int foo(int x,int i,int sum) {
    if (i < x) {
        i += 1;
        sum += i;
        foo(x, i, sum);
    }
    else {
        return sum;
    }  
}

int main()
{
    int n,i = 0,sum = 0;
    std::cin >> n;
    std::cout << foo(n, i, sum); 
}

Leave a Comment