Topics
Introduction
In this article, I have shared the list of all Star (*) pattern programs in the c programming language. We will learn to create different patterns or a geometrical shape such as square, triangle, etc. To understand these C programming examples, you should have the knowledge C programming topics such as C for Loop, C if .else Statement, C while and do…while Loop, C break and continue statement.
I have used Code:: Blocks IDE for debugging purposes. But you can use any C programming language compiler as per your availability.
1. C program to print right Angled triangle star pattern
#include <stdio.h> int main() { int i, j; for(i=1;i<=5;i++) { for(j=1;j<=i;j++) { printf("*"); } printf("\n"); } return 0; }
2. C program to print mirrored right triangle star pattern
#include <stdio.h> int main() { int i, j, k; for(i=5;i>=1;i--) { for(j=1;j<i;j++) { printf(" "); } for(k=5;k>=i;k--) { printf("*"); } printf("\n"); } return 0; }
3. C program to print Inverted Right Triangle Star Pattern
#include <stdio.h> int main() { int i, j; for(i=5;i>=1;i--) { for(j=1;j<=i;j++) { printf("*"); } printf("\n"); } return 0; }
4. C program to print Inverted Mirrored Right Triangle Star Pattern
#include <stdio.h> int main() { int i, j, k; for(i=5;i>=1;i--) { for(j=5;j>i;j--) { printf(" "); } for(k=1;k<=i;k++) { printf("*"); } printf("\n"); } return 0; }
5. C program to print Square Star Pattern
***** ***** ***** ***** *****
#include <stdio.h> int main() { int i, j; for(i=1; i<=5; i++) { for(j=1; j<=5; j++) { printf("*"); } printf("\n"); } return 0; }
6. C program to print Mirrored Rhombus Star Pattern
***** ***** ***** ***** *****
#include <stdio.h> int main() { int i, j; for(i=1; i<=5; i++) { for(j=1; j<i; j++) { printf(" "); } for(j=1; j<=5; j++) { printf("*"); } printf("\n"); } return 0; }
7. C program to print Hollow Right Triangle Star Pattern
#include <stdio.h> int main(){ int i, j; for(i=1; i<=5; i++) { for(j=1; j<=i; j++) { if(j==1 || j==i || i==5) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0; }
8. C program to print Hollow Mirrored Right Triangle Star Pattern
#include <stdio.h> int main() { int i, j; for(i=1; i<=5; i++) { for(j=i; j<5; j++) { printf(" "); } for(j=1; j<=i; j++) { if(i==5 || j==1 || j==i) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0; }
9. C program to print Pyramid Star Pattern
* *** ***** ******* *********
#include <stdio.h> int main() { int i, j, k; for(i=1;i<=5;i++) { for(j=i;j<5;j++) { printf(" "); } for(k=1;k<(i*2);k++) { printf("*"); } printf("\n"); } return 0; }
10. C program to print Inverted Pyramid Star Pattern
#include <stdio.h> int main() { int i, j, k; for(i=5;i>=1;i--) { for(j=5;j>i;j--) { printf(" "); } for(k=1;k<(i*2);k++) { printf("*"); } printf("\n"); } return 0; }
11. C program to print Hollow Pyramid Star Pattern
#include <stdio.h> int main() { int i, j; for(i=1; i<=5; i++) { for(j=i; j<5; j++) { printf(" "); } for(j=1; j<=(2*i-1); j++) { if(i==5 || j==1 || j==(2*i-1)) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0; }
12. C program to print hollow inverted pyramid star program
#include <stdio.h> int main() { int i, j; for(i=5; i>=1; i--) { for(j=i; j<5; j++) { printf(" "); } for(j=1; j<=(2*i-1); j++) { if(i==5 || j==1 || j==(2*i-1)) { printf("*"); } else { printf(" "); } } printf("\n"); } return 0; }
13. C program to print Half Diamond Star Pattern
* ** *** **** ***** **** *** ** *
#include <stdio.h> int main() { int i, j; for(i=1; i<=5; i++) { for(j=1; j<=i; j++) { printf("*"); } printf("\n"); } for(i=5; i>=1; i--) { for(j=1; j<i; j++) { printf("*"); } printf("\n"); } return 0; }
14. C program to print Mirrored Half Diamond Star Pattern
* ** *** **** ***** **** *** ** *
#include <stdio.h> int main() { int i, j; for(i=1; i<=5; i++) { for(j=i; j<5; j++) { printf(" "); } for(j=1; j<=i; j++) { printf("*"); } printf("\n"); } for(i=5; i>=1; i--) { for(j=i; j<=5; j++) { printf(" "); } for(j=1; j<i; j++) { printf("*"); } printf("\n"); } return 0; }
15. C program to print Diamond Star Pattern
#include <stdio.h> int main() { int i, j; for(i=1; i<=5; i++) { for(j=i; j<5; j++) { printf(" "); } for(j=1; j<=(2*i-1); j++) { printf("*"); } printf("\n"); } for(i=5; i>=1; i--) { for(j=i; j<=5; j++) { printf(" "); } for(j=2; j<(2*i-1); j++) { printf("*"); } printf("\n"); } return 0; }
16. C program to print Hollow diamond star pattern
* * * * * * * * * * * * * * * *
#include <stdio.h> int main() { int i, j; for(i=1; i<=5; i++) { for(j=5; j>i; j--) { printf(" "); } printf("*"); for(j=1; j<(i-1)*2; j++) { printf(" "); } if(i==1) printf("\n"); else printf("*\n"); } for(i=4; i>=1; i--) { for(j=5; j>i; j--) { printf(" "); } printf("*"); for(j=1; j<(i-1)*2; j++) { printf(" "); } if(i==1) printf("\n"); else printf("*\n"); } return 0; }
Also check