C program to print the right half star pyramid pattern
codeaft.c
#include <stdio.h> int main() { int i, j; for (i = 1; i <= 10; i++) { for (j = 1; j <= i; j++) { printf("*"); } printf("\n"); } }
Output
codeaft@codeaft:~$ gcc codeaft.c
codeaft@codeaft:~$ ./a.out * ** *** **** ***** ****** ******* ******** ********* ********** codeaft@codeaft:~$
C program to print the left half star pyramid pattern
codeaft.c
#include <stdio.h> int main() { int i, j; for (i = 1; i <= 10; i++) { for (j = 1; j <= 10 - i; j++) printf(" "); for (j = 1; j <= i; j++) { printf("*"); } printf("\n"); } return 0; }
Output
codeaft@codeaft:~$ gcc codeaft.c
codeaft@codeaft:~$ ./a.out * ** *** **** ***** ****** ******* ******** ********* ********** codeaft@codeaft:~$
C program to print the inverted right half star pyramid pattern
codeaft.c
#include <stdio.h> int main() { int i, j; for (i = 10; i >= 1; i--) { for (j = 1; j <= i; j++) { printf("*"); } printf("\n"); } return 0; }
Output
codeaft@codeaft:~$ gcc codeaft.c
codeaft@codeaft:~$ ./a.out ********** ********* ******** ******* ****** ***** **** *** ** * codeaft@codeaft:~$
C program to print the inverted left half star pyramid pattern
codeaft.c
#include <stdio.h> int main() { int i, j; for (i = 10; i >= 1; i--) { for (j = 1; j <= 10 - i; j++) printf(" "); for (j = 1; j <= i; j++) { printf("*"); } printf("\n"); } return 0; }
Output
codeaft@codeaft:~$ gcc codeaft.c
codeaft@codeaft:~$ ./a.out ********** ********* ******** ******* ****** ***** **** *** ** * codeaft@codeaft:~$
Comments and Reactions