2.16: Diamond Pattern
Write a <span style="text-decoration-line: none;">program</span> that displays the following pattern:
*
***
*****
*******
*****
***
*
#include <iostream>
using namespace std;
int main()
{
int i, j, n;
//Number of rows must be an odd number
n=7; //Let 9 be the number of rows
i= 1;
while(i <= n){
j = 1;
while(j <= i){
cout << "* ";
j++;
}
i+=2;
cout << "\n";
}
i = 5; //Should be less than rows by 2
while( i >= 1){
j = 1;
while(j <= i){
cout << "* ";
j++;
}
cout << "\n";
i -= 2;
}
return 0;
}
Comments
Leave a comment