G
Guest
Hello All, this is my first post.
OK - The goal is to display the following (note: substitute 1' ' for 2'*')
by using 3 recursive functions.
0123454321001234543210
**012343210012343210**
****01232100123210****
******0121001210******
********010010********
**********00**********
**********00**********
********010010********
******0121001210******
****01232100123210****
**012343210012343210**
0123454321001234543210
Obviously, I'm having trouble with the exact specs, but I'm looking for
guidance in the spacing aspect - I'm close with the digits (my code produces
one half of the display)- Thanks
#include <iostream>
#include <string>
using namespace std;
void Fun1 (int);
void Fun2 (int, int);
void Fun3 (int);
int main()
{
cout <<"Enter an integer between 1 and 9 : ";
int Value;
cin >> Value;
int count = 0;
while (Value > count)
{
Fun2 (0, Value);
Fun1 (Value);
Fun2 (0, Value);
cout <<endl;
Fun1 (Value);
// Fun3 (Value);
--Value;
}
return 0;
}
void Fun1 (int n)
{
char c = ' ';
string space = "";
int i = n;
n = n - (i - 1);
while (i <= n)
{
cout<<n;
++i;
}
}
/*
string Reverse (int Number)
{
string s = "";
string c;
for(int bit; Number != 0
{
bit = Number % 2;
Number = Number / 2;
c = char ('0' + bit);
s = s + c;
}
cout <<s<<endl<<endl;
return s;
}
*/
void Fun2 (int current, int stopval)
{
cout <<current;
if (current < stopval)
{
Fun2(current + 1, stopval);
cout << current;
}
}
/*void Fun3 (int descend)
{
while (descend >= 0)
{
cout <<descend;
descend--;
}
cout << endl;
}
*/
OK - The goal is to display the following (note: substitute 1' ' for 2'*')
by using 3 recursive functions.
0123454321001234543210
**012343210012343210**
****01232100123210****
******0121001210******
********010010********
**********00**********
**********00**********
********010010********
******0121001210******
****01232100123210****
**012343210012343210**
0123454321001234543210
Obviously, I'm having trouble with the exact specs, but I'm looking for
guidance in the spacing aspect - I'm close with the digits (my code produces
one half of the display)- Thanks
#include <iostream>
#include <string>
using namespace std;
void Fun1 (int);
void Fun2 (int, int);
void Fun3 (int);
int main()
{
cout <<"Enter an integer between 1 and 9 : ";
int Value;
cin >> Value;
int count = 0;
while (Value > count)
{
Fun2 (0, Value);
Fun1 (Value);
Fun2 (0, Value);
cout <<endl;
Fun1 (Value);
// Fun3 (Value);
--Value;
}
return 0;
}
void Fun1 (int n)
{
char c = ' ';
string space = "";
int i = n;
n = n - (i - 1);
while (i <= n)
{
cout<<n;
++i;
}
}
/*
string Reverse (int Number)
{
string s = "";
string c;
for(int bit; Number != 0
{
bit = Number % 2;
Number = Number / 2;
c = char ('0' + bit);
s = s + c;
}
cout <<s<<endl<<endl;
return s;
}
*/
void Fun2 (int current, int stopval)
{
cout <<current;
if (current < stopval)
{
Fun2(current + 1, stopval);
cout << current;
}
}
/*void Fun3 (int descend)
{
while (descend >= 0)
{
cout <<descend;
descend--;
}
cout << endl;
}
*/