Hi all.. This function should work recursively.. Meaning call the function inside the same function.
So i'm supposed to write a recursive function that takes a single parameter from type integer and decrements that number until it reaches zero.
Ex. If the user entered 7, he'll get this output:
7 6 5 4 3 2 1 0
This is my code.. But it is not working :s It keep returning the same number to me no matter what changes make.. :s
Would you check it please?
#include <iostream>
using namespace std;
int decrement (int n);
int main ()
{
int number;
cout<<"Enter a number to decrement it."<<endl;
cin>> number;
decrement (number);
return 0;
}
int decrement (int n)
{
if (n>=1)
return n;
else
{
decrement(n-1);
return n;
}
}