KEMBAR78
C Pattern Programs | PDF | Computer Programming | Computer Standards
0% found this document useful (0 votes)
10 views5 pages

C Pattern Programs

These are the important topic to learn

Uploaded by

yindu8348
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)
10 views5 pages

C Pattern Programs

These are the important topic to learn

Uploaded by

yindu8348
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

C Language Pattern Programs

Right-angled Triangle (Stars)


*
* *
* * *
* * * *
* * * * *

#include <stdio.h>
int main() {
int i, j, n;
printf("Enter rows: ");
scanf("%d", &n);
for(i = 1; i <= n; i++) {
for(j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
return 0;
}

Inverted Triangle (Stars)


* * * * *
* * * *
* * *
* *
*

#include <stdio.h>
int main() {
int i, j, n;
printf("Enter rows: ");
scanf("%d", &n);
for(i = n; i >= 1; i--) {
for(j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
return 0;
}

Number Triangle
1
1 2
1 2 3
1 2 3 4

#include <stdio.h>
int main() {
int i, j, n;
printf("Enter rows: ");
scanf("%d", &n);
for(i = 1; i <= n; i++) {
for(j = 1; j <= i; j++) {
printf("%d ", j);
}
printf("\n");
}
return 0;
}

Pyramid (Stars)
*
* *
* * *
* * * *
* * * * *

#include <stdio.h>
int main() {
int i, j, space, n;
printf("Enter rows: ");
scanf("%d", &n);
for(i = 1; i <= n; i++) {
for(space = 1; space <= n - i; space++) {
printf(" ");
}
for(j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
return 0;
}

Diamond (Stars)
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*

#include <stdio.h>
int main() {
int i, j, space, n;
printf("Enter rows: ");
scanf("%d", &n);
// Upper pyramid
for(i = 1; i <= n; i++) {
for(space = 1; space <= n - i; space++) {
printf(" ");
}
for(j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
// Lower pyramid
for(i = n-1; i >= 1; i--) {
for(space = 1; space <= n - i; space++) {
printf(" ");
}
for(j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
return 0;
}

Alphabet Triangle
A
A B
A B C
A B C D

#include <stdio.h>
int main() {
int i, j, n;
printf("Enter rows: ");
scanf("%d", &n);
for(i = 1; i <= n; i++) {
for(j = 1; j <= i; j++) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
return 0;
}

Repeated Alphabet Triangle


A
B B
C C C
D D D D

#include <stdio.h>
int main() {
int i, j, n;
printf("Enter rows: ");
scanf("%d", &n);
for(i = 0; i < n; i++) {
for(j = 0; j <= i; j++) {
printf("%c ", 'A' + i);
}
printf("\n");
}
return 0;
}
Alphabet Pyramid
A
A B
A B C
A B C D
A B C D E

#include <stdio.h>
int main() {
int i, j, space, n;
printf("Enter rows: ");
scanf("%d", &n);
for(i = 1; i <= n; i++) {
for(space = 1; space <= n - i; space++) {
printf(" ");
}
for(j = 1; j <= i; j++) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
return 0;
}

Alphabet Diamond
A
A B
A B C
A B C D
A B C D E
A B C D
A B C
A B
A

#include <stdio.h>
int main() {
int i, j, space, n;
printf("Enter rows: ");
scanf("%d", &n);
// Upper part
for(i = 1; i <= n; i++) {
for(space = 1; space <= n - i; space++) {
printf(" ");
}
for(j = 1; j <= i; j++) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
// Lower part
for(i = n-1; i >= 1; i--) {
for(space = 1; space <= n - i; space++) {
printf(" ");
}
for(j = 1; j <= i; j++) {
printf("%c ", 'A' + j - 1);
}
printf("\n");
}
return 0;
}

You might also like