Hi everyone, I need to write a recursive function that accepts a positive integer, n , and calculates the following sum of integers between 3 and n, inclusive, that are divisible by 3. ex. 3 + 6 + 9....
Im away from a compiler so I cant test it but so far I have...
Am I on the right track?Code:int n;
int temp;
int recur(n)
{
if (n <= 1 ) return 1;
temp = n + recur(n-3);
return temp;
}
void main()
{
cin >> n;
n = n - (n % 3);
recur(n);
}
Thanks!