#include <stdlib.h>
#include <iostream>
#include <stdio.h>
#include <cstdlib>
using namespace std;
void recursion(int p)
{
static int i = 10;
if (p == i) return;
if (p > i)
{
--p;
if (p > 10) cout<<p<<" ";
recursion(p);
}
else
{
++p;
if (p < 10) cout<<p<<" ";
recursion(p);
}
}
void iterative(int p)
{
if (p > 10)
{
for (int i = p; i > 10; --i)
if (i < p) { cout<<i<<" ";}
}
else
{
for (int i = p; i < 10; ++i)
if (i > p) { cout<<i<<" ";}
}
}
int main()
{
int n;
cout<<"Enter the N : ";
cin>>n;
cout<<"all integers between "<<n<<" and 10 : "<<endl;
cout<<"recursion : ";
recursion(n); cout<<endl;
cout<<"recursion : ";
iterative(n); cout<<endl;
system("pause");
return 0;
}
Comments
Leave a comment