64 564
Assignments Done
99,3%
Successfully Done
In September 2018

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?
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions