How is it possible to print the following pattern?
*
**
***
****
*****
****
***
**
*
How can we add the spaces during the first half of the pattern? I only managed to get the second half of the pattern right:
#include <iostream>
using namespace std;
void printpattern(int n)
{
for (int r = 0; r <= n; r++)
{
for (int z = 0; z <= r; z++) {
cout << "*";
}
cout << endl;
}
}
int main()
{
int n = 5;
printpattern(n);
}