Answer to Question #48288 in C++ for CaptainNoobz

Question #48288
How do I write a pseudo code for a recursive procedure that takes an integer N as a parameter, and prints all integers between N and 10. And how do I do it for an iterative procedure?
1
Expert's answer
2014-10-28T01:39:37-0400
#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;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS