0% found this document useful (0 votes)
7 views

Pattern Printing

Uploaded by

mohit18gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Pattern Printing

Uploaded by

mohit18gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

*Pattern 1: Full Pyramid*

```

#include <iostream>

using namespace std;

int main() {

int n;

cout << "Enter number of rows: ";

cin >> n;

for (int i = 0; i < n; i++) {

for (int j = 0; j < n - i - 1; j++) {

cout << " ";

for (int k = 0; k <= i; k++) {

cout << "* ";

cout << endl;

return 0;

```
*Output:*

```

**

***

****

*****

```

*Pattern 2: Hollow Pyramid*

```

#include <iostream>

using namespace std;

int main() {

int n;

cout << "Enter number of rows: ";

cin >> n;

for (int i = 0; i < n; i++) {

for (int j = 0; j < n - i - 1; j++) {

cout << " ";

for (int k = 0; k <= i; k++) {


if (k == 0 || k == i || i == n - 1) {

cout << "* ";

} else {

cout << " ";

cout << endl;

return 0;

```

*Output:*

```

**

* *

* *

*****

```

*Pattern 3: Inverted Pyramid*

```

#include <iostream>
using namespace std;

int main() {

int n;

cout << "Enter number of rows: ";

cin >> n;

for (int i = n; i >= 1; i--) {

for (int j = 0; j < n - i; j++) {

cout << " ";

for (int k = 0; k < i; k++) {

cout << "* ";

cout << endl;

return 0;

```

*Output:*

```

*****

****

***
**

```

*Pattern 4: Diamond*

```

#include <iostream>

using namespace std;

int main() {

int n;

cout << "Enter number of rows: ";

cin >> n;

for (int i = 0; i < n; i++) {

for (int j = 0; j < n - i - 1; j++) {

cout << " ";

for (int k = 0; k <= i; k++) {

cout << "* ";

cout << endl;

for (int i = n - 2; i >= 0; i--) {

for (int j = 0; j < n - i - 1; j++) {


cout << " ";

for (int k = 0; k <= i; k++) {

cout << "* ";

cout << endl;

return 0;

```

*Output:*

```

**

***

****

*****

****

***

**

```

*Pattern 5: Hollow Diamond*


```

#include <iostream>

using namespace std;

int main() {

int n;

cout << "Enter number of rows: ";

cin >> n;

for (int i = 0; i < n; i++) {

for (int j = 0; j < n - i - 1; j++) {

cout << " ";

for (int k = 0; k <= i; k++) {

if (k == 0 || k == i || i == n - 1) {

cout << "* ";

} else {

cout << " ";

cout << endl;

for (int i = n - 2; i >= 0; i--) {

for (int j = 0; j < n - i - 1; j++) {

cout << " ";


}

for (int k = 0; k <= i; k++) {

if (k == 0 || k == i || i == 0) {

cout << "* ";

} else {

cout << " ";

cout << endl;

return 0;

```

*Output:*

```

```

You might also like