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

Pattern Printing In C

Pattern

Uploaded by

sshafick748
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)
22 views

Pattern Printing In C

Pattern

Uploaded by

sshafick748
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/ 5

1.

Simple Right-Angled Triangle Pattern

**

***

****

*****

Code:

#include <stdio.h>

int main() {

int rows;

printf("Enter number of rows: ");

scanf("%d", &rows);

for (int i = 1; i <= rows; i++) { // Loop for each row

for (int j = 1; j <= i; j++) { // Print stars in each row

printf("* ");

printf("\n"); // Move to the next line after each row

return 0;

2. Inverted Right-Angled Triangle

*****

****

***

**

*
Code :

#include <stdio.h>

int main() {

int rows;

printf("Enter number of rows: ");

scanf("%d", &rows);

for (int i = rows; i >= 1; i--) { // Start with the max row count and decrease

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

printf("* ");

printf("\n");

return 0;

3. Pyramid Pattern

**

***

****

*****

Code:

#include <stdio.h>

int main() {

int rows;

printf("Enter number of rows: ");


scanf("%d", &rows);

for (int i = 1; i <= rows; i++) {

// Print spaces

for (int j = i; j < rows; j++) {

printf(" ");

// Print stars

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

printf("* ");

printf("\n");

return 0;

4. Diamond Pattern

**

***

****

*****

****

***

**

Code :

#include <stdio.h>

int main() {

int rows;
printf("Enter number of rows: ");

scanf("%d", &rows);

// Upper part of diamond

for (int i = 1; i <= rows; i++) {

// Print spaces

for (int j = i; j < rows; j++) {

printf(" ");

// Print stars

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

printf("* ");

printf("\n");

// Lower part of diamond

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

// Print spaces

for (int j = rows; j > i; j--) {

printf(" ");

// Print stars

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

printf("* ");

printf("\n");

return 0;

}
5. Number Pyramid (Bonus)

Instead of stars, here’s a pattern with numbers:

12

123

1234

12345

Code:

#include <stdio.h>

int main() {

int rows;

printf("Enter number of rows: ");

scanf("%d", &rows);

for (int i = 1; i <= rows; i++) {

// Print spaces

for (int j = i; j < rows; j++) {

printf(" ");

// Print numbers

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

printf("%d ", k);

printf("\n");

return 0;

You might also like