- We can print *'s in pyramid pattern using C programming language.
- We can also print patterns of numbers and alphabets using C program.
- Now Check below program that how to print pyramid pattern of * using C program using for loop.
- C program to print patterns of numbers and stars in a pyramid shape
Program #1 : Write a C program to print pyramid pattern of numbers using for loop.
- #include <stdio.h>
- #include <stdlib.h>
- int main(){
- int i, j, rows;
- printf("Enter number of rows: \n");
- scanf("%d",&rows);
- for(i=1; i<=rows; ++i)
- {
- for(j=1; j<=i; ++j)
- {
- printf("* ");
- }
- printf("\n");
- }
- getch();
- }
Output:
Program #2 : Write a C program to print pyramid pattern of numbers using for loop.
- #include <stdio.h>
- #include <stdlib.h>
- int main(){
- int i, j, rows;
- printf("Enter number of rows to print pyramid numbers pattern \n ");
- scanf("%d",&rows);
- for(i=1; i<=rows; ++i)
- {
- for(j=1; j<=i; ++j)
- {
- printf("%d ",j);
- }
- printf("\n");
- }
- return 0;
- }
Output:
- Enter number of rows to print pyramid numbers pattern
- 10
- 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
- 1 2 3 4 5 6 7 8
- 1 2 3 4 5 6 7 8 9
- 1 2 3 4 5 6 7 8 9 10
Program #3 : Write a c program to print patterns of numbers and alphabets
- #include <stdio.h>
- #include <stdlib.h>
- int main(){
- int i, j;
- char input, alphabet = 'A';
- printf("Enter the uppercase character you want to print in 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");
- }
- getch();
- }
Output:
- Enter the uppercase character you want to print in last row:
- I
- A
- BB
- CCC
- DDDD
- EEEEE
- FFFFFF
- GGGGGGG
- HHHHHHHH
- IIIIIIIII
A
ReplyDelete1 1
B B B
2 2 2 2
C C C C C
How to print this pattern
A
ReplyDelete2 3