recursive functions

can someone help me please! i want to write a C++ program which can show this as an out put:
****
***
**
*
*
**
***
****

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
#include <string>

using namespace std;

void output(const char ch, int times)
{
	string s(times, ch);
	cout << s << endl;
	if (--times)
		output(ch, times);
	cout << s << endl;
}

int main()
{
	output('*', 4);
}
this wat i hv done nd it shows no output:

#include <iostream>

using namespace std;

void DisplayLine(int n, int nDepth)
{ int i;
for(i = 4; i < n; i++)
cout << "*";
cout << endl;
if(n <= nDepth)
return ;
DisplayLine( n+1, nDepth);
for(i = 0; i < n; i--)
cout << "*";
cout << endl;
return ;
}
int main(void)
{
int nDepth= 4;
int n = 4;
cout << endl << endl;
DisplayLine(0, nDepth);
system("pause");
return 0;
}
Well in your code you are setting n in DisplayLine(...) to 0 from the call in main(). So the code inside your two for(...) loops isn't called.

Anyway, I supplied you some very simple code that does what you asked for!
Topic archived. No new replies allowed.