#include <iostream>
using namespace std;
int main()
// Number of rows
int N = 5;
// Outer loop runs N times, once for each row
for (int i = 1; i <= N; i++) {
// Inner loop prints 'i' stars
for (int j = 1; j <= i; j++) {
cout << "*";
cout << "\n";
return 0;
}
#include <iostream>
using namespace std;
int main()
int N = 5;
for (int i = 0; i <= N; i++) {
// Inner loop prints 'N - i ' stars
for (int j = 1; j <= N - i ; j++) {
cout << "*";
cout << "\n";
return 0;
Problem 2
This program prints a 7 × 7 star pattern that includes:
Top boundary
Bottom boundary
Left boundary
Right boundary
Main diagonal
Secondary diagonal
All other positions are filled with spaces
i == 0 Top row
i == n - 1 Bottom row
j == 0 Left column
j == n - 1 Right column
i == j Main diagonal
i + j == n - 1 Secondary diagonal
int main() {
int n = 7;
// Loop denoting rows
for (int i = 0; i < n; i++) {
// Loop denoting columns
for (int j = 0; j < n; j++) {
// Checking boundary conditions and main
// diagonal and secondary diagonal conditions
if (i == 0 || j == 0 || i == j || i == n - 1 || j == n - 1 || i + j == n - 1)
cout << "*";
else
cout << " ";
cout << "\n";
return 0;
int main()
// Number of rows
int N = 5;
for (int i = 1; i <= N; i++) {
// Inner loop prints 'i - 1' spaces
for (int j = 1; j <= i - 1; j++) {
cout << " ";
// Inner loop prints 'N - i + 1' stars
for (int j = 1; j <= N - i + 1; j++) {
cout << "*";
cout << "\n";
return 0;
int main()
int N = 5;
// Outer loop runs N times, once for each row
for (int i = 1; i <= N; i++) {
// Inner loop prints 'N - i' spaces
for (int j = 1; j <= N - i; j++) {
cout << " ";
}
// Inner loop prints '2 * i - 1' stars
for (int j = 1; j <= 2 * i - 1; j++) {
cout << "*";
cout << "\n";
return 0;
int main()
// Number of rows
int N = 5
// Outer loop runs N times, once for each row
for (int i = 1; i <= N; i++) {
// Inner loop prints 'i - 1' spaces
for (int j = 1; j <= i - 1; j++) {
cout << " ";
// Inner loop prints '2 * (N - i) + 1' stars
for (int j = 1; j <= 2 * (N - i) + 1; j++) {
cout << "*";
}
cout << "\n";
return 0;
*****
****
***
**
*
**
***
****
*****
Problem 1: Write a Program to Print Hourglass Pattern
#include <iostream>
using namespace std;
int main() {
int i, j, k, n = 5;
for (i = 1; i <= n; i++) {
for (j = 1; j < i; j++) {
cout << ' ';
for (k = i; k <= n; k++) {
cout << "* ";
cout << "\n";
}
for (i = n - 1; i >= 1; i--) {
for (j = 1; j < i; j++) {
cout << ' ';
for (k = i; k <= n; k++) {
cout << "* ";
cout << "\n";
return 0;