This Problem is on Hackerblocks.
My one test case is failing why ??
Take as input N, a number. Print odd numbers in decreasing sequence (up until 0) and even numbers in increasing sequence (up until N) using Recursion
if n is odd you have to subtract 1 from n to make it even i have done some change in your code
#include
using namespace std;
void even(int e,int n){
if(e>n){
return;
}
cout<<e<<endl;
even(e+2,n);
}
void odd(int n){
if(n<=0){
return;
}cout<<n<<endl;
odd(n-2);
}
int main() {
int n;
cin>>n;
if(n&1){
odd(n);
even(2,n-1);
}else{ odd(n-1);even(2,n);}
return 0;
}