this program is trying to add from 1.. to x with return function.
but when I enter 10 sum is 54 which is wrong. 1,2,3,4,5,6,7,8,9,10 = 55

#include <cstdlib>
#include <iostream>

int burcin(int);

using namespace std;

int main(int argc, char *argv[])
    int x;
    int ft=0;
    cout << "enter the number=\n";
    cin >> x;
    cout << "from 1"<<"to"<<x<<"\ntotal value="<<ft<<endl;
    return EXIT_SUCCESS;

int burcin(int x)
     if (x==1)  return 0; 
     return (x+ burcin(x-1));

you could cheat and return

return ((pow(x,2)+x)/2);

Edited 6 Years Ago by kes166: n/a

maybe also if theres don't work try declaring a global variable and set it equal to (x+ burcin(x-1))

then just return the variable

This question has already been answered. Start a new discussion instead.