Could anyone tell me how to modify my code.
I want to print a diamond pattern using only two loops. If I enter 5, the diamond should be like this:
*
***
*****
***
*
I am half way done.
here is what I got so far.
5
*
***
*****
****
***
Below is my code:
#include <iostream>
using namespace std;
// print diamond. Instead of finding * pattern, just find " " 's pattern.
int main()
{
int size;
cin >> size;
int m = size / 2;
for (int row = 0; row < size; row++) {
for (int col = 0; col < size; col++) { // Before || is the left part. After || is right part
if ((row < m && (col < m - row || col > m + row)) || (row > m && col < row - m))
cout << " ";
else
cout << "*";
}
cout << endl;
}
return 0;
}