C Program To Print Pyramids & Patterns -सी प्रोग्राम पिरामिड और पैटर्न प्रिंट करने के लिए
- _Romeyo Boy_
- 22 दिस॰ 2021
- 5 मिनट पठन
अपडेट करने की तारीख: 23 दिस॰ 2021

इस उदाहरण में, आप C प्रोग्रामिंग में निम्न प्रोग्राम्स को प्रिंट करना, बनाना सीखेंगे।
Half Pyramids ( आधे पिरामिड )
Inverted Pyramids ( उल्टे पिरामिड )
Full Pyramids ( पूर्ण पिरामिड )
Inverted Full Pyramids ( उल्टे पूर्ण पिरामिड )
Pascal's Triangle ( पास्कल के त्रिकोण )
Floyd's Triangle ( फ़्लॉइड के त्रिकोण )
इस उदाहरण को समझने के लिए, आपको निम्नलिखित सी प्रोग्रामिंग विषयों का ज्ञान होना चाहिए;
C if...else Statement
C for Loop
C while and do...while Loop
C break and continue
यहां उन प्रोग्राम्स की सूची दी गई है, जो आपको इस उदाहरण पृष्ठ पर मिलेंगे।

C Programs Examples, Practices, Exercise & Solutions
Half pyramid of *
Half pyramid of numbers
Half pyramid of alphabets
Inverted half pyramid of *
Inverted half pyramid of numbers
Full pyramid of *
Full pyramid of numbers
Inverted full pyramid of *
Pascal's triangle
Floyd's triangle
< > Program Example : 01 | Half Pyramid of *
#include <stdio.h>
#include <conio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
♻ This Program Output Is :
Enter the number of rows: 7
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
< > Program Example : 02 | Half Pyramid Of Numbers
#include <stdio.h>
#include <conio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i) {
for (j = 1; j <= i; ++j) {
printf("%d ", j);
}
printf("\n");
}
return 0;
}
♻ This Program Output Is :
Enter the number of rows: 7
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
< > Program Example : 03 | Half Pyramid Of Alphabets
#include <stdio.h>
#include <conio.h>
int main()
{
int i, j;
char input, alphabet = 'A';
printf("Enter an uppercase character you want to print in the last row: ");
scanf("%c", &input);
for (i = 1; i <= (input - 'A' + 1); ++i) {
for (j = 1; j <= i; ++j) {
printf("%c ", alphabet);
}
++alphabet;
printf("\n");
}
return 0;
}
♻ This Program Output Is :
A
B B
C C C
D D D D
E E E E E
< > Program Example : 04 | Inverted Half Pyramid Of Star (*)
#include <stdio.h>
#include <conio.h>
int main() {
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("* ");
}
printf("\n");
}
return 0;
}
♻ This Program Output Is :
Enter the number of rows: 7
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
< > Program Example : 05 | Inverted Half Pyramid Of Numbers
#include <stdio.h>
#include <conio.h>
int main()
{
int i, j, rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (j = 1; j <= i; ++j) {
printf("%d ", j);
}
printf("\n");
}
return 0;
}
♻ This Program Output Is :
Enter the number of rows: 7
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
< > Program Example : 06 | Full Pyramid Of Star ( * )
#include <stdio.h>
#include <conio.h>
int main()
{
int i, space, rows, k = 0;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i, k = 0) {
for (space = 1; space <= rows - i; ++space) {
printf(" ");
}
while (k != 2 * i - 1) {
printf("* ");
++k;
}
printf("\n");
}
return 0;
}
♻ This Program Output Is :
Enter the number of rows: 5
*
* * *
* * * * *
* * * * * * *
* * * * * * * * *
< > Program Example : 07 | Full Pyramid Of Numbers
#include <stdio.h>
#include <conio.h>
int main()
{
int i, space, rows, k = 0, count = 0, count1 = 0;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; ++i) {
for (space = 1; space <= rows - i; ++space) {
printf(" ");
++count;
}
while (k != 2 * i - 1) {
if (count <= rows - 1) {
printf("%d ", i + k);
++count;
} else {
++count1;
printf("%d ", (i + k - 2 * count1));
}
++k;
}
count1 = count = k = 0;
printf("\n");
}
return 0;
}
♻ This Program Output Is :
Enter the number of rows: 5
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
5 6 7 8 9 8 7 6 5
< > Program Example : 08 | Inverted full pyramid Of Star ( * )
#include <stdio.h>
#include <conio.h>
int main()
{
int rows, i, j, space;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = rows; i >= 1; --i) {
for (space = 0; space < rows - i; ++space)
printf(" ");
for (j = i; j <= 2 * i - 1; ++j)
printf("* ");
for (j = 0; j < i - 1; ++j)
printf("* ");
printf("\n");
}
return 0;
}
♻ This Program Output Is :
Enter the number or rows: 5
* * * * * * * * *
* * * * * * *
* * * * *
* * *
*
< > Program Example : 09 | Pascal's Triangle
#include <stdio.h>
#include <conio.h>
int main() {
int rows, coef = 1, space, i, j;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 0; i < rows; i++) {
for (space = 1; space <= rows - i; space++)
printf(" ");
for (j = 0; j <= i; j++) {
if (j == 0 || i == 0)
coef = 1;
else
coef = coef * (i - j + 1) / j;
printf("%4d", coef);
}
printf("\n");
}
return 0;
}
♻ This Program Output Is :
Enter the number of rows: 6
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
< > Program Example : 10 | Floyd's Triangle
#include <stdio.h>
#include <conio.h>
int main()
{
int rows, i, j, number = 1;
printf("Enter the number of rows: ");
scanf("%d", &rows);
for (i = 1; i <= rows; i++) {
for (j = 1; j <= i; ++j) {
printf("%d ", number);
++number;
}
printf("\n");
}
return 0;
}
♻ This Program Output Is :
Enter the number of rows: 5
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
Comentarios