Expand|Select|Wrap|Line Numbers
- *
- * *
- * * *
- * * * *
- * * *
- * *
- *
I understand the general idea and have managed to put together the following code.
Expand|Select|Wrap|Line Numbers
- void print(int n)
- {
- if (n == 0)
- {
- return;
- }
- else
- {
- print(n-1);
- cout << '*' * n << endl;
- }
- }
This source code compiles, however it prints:
42
84
126
168
which sounds like the ASCII codes multiplied by n. I'm guessing this is because when I am multiplying by an integer it converts the char to an integer as well.
Firstly, is there any way to stop this happening, and is there anyway to create the spaces without using a loop ?
Thanking anyone who responds.