Star Pattern in C with Code Samples

A pattern program in the C language is quite an easy and fun way to practice loops as well as logical thinking. Pattern program just means printing different shapes like pyramid, triangle, diamond, star, alphabets, and numbers using C code.

Learning this pattern program in C will help you understand clearly how nested loops and different conditions work. Such types of programs are mostly used in coding interviews, programming competitions, and also college tests, logic as well and coding skills.

Blogging Illustration

Star Pattern in C with Code Samples

image

Below are easy ways to print patterns clearly and step by step. This just makes it simple for beginners to master the art of C programming and gain great knowledge.

Option 1: C Pattern Program for Right-Angled Triangle

Program code :

                        #include 

                        int main() {
                            int i, j, rows = 5;
                            for(i = 1; i <= rows; i++) { for(j="1;" j <="i;" j++) printf("*"); } printf("\n"); return 0; output : * ** *** **** ***** pre>
                    

Explanation of code :

  • This triangle program will print simple right-angled triangles using stars.
  • Nested loops are used where the outer loop will just control rows, and the inner loop will print stars.
  • Such basic types of C programs in patterns help beginners to understand loops easily.

Option 2: C Pattern Program for Inverted Right-Angled Triangle

Program code :

                            #include 

                            int main() {
                                int i, j, rows = 5;
                                for(i = rows; i >= 1; i--) {
                                    for(j = 1; j <= i; j++) { printf("*"); } printf("\n"); return 0; output : ***** **** *** ** * < pre>
                    

Explanation of code :

  • This pattern program will print an inverted pattern right-angled triangle.
  • The outer loop will just run in reverse, which is decreasing row size, and the inner loop will help in printing stars for each row.
  • More complicated patterns can be easily created if you learn this inverted triangle pattern.
  • This triangle pattern is asked in beginner-level coding exams.

Option 3: Pattern Program in C For an Equilateral Triangle

Program code :

                            #include 

                            int main() {
                                int i, space, j, rows = 5;
                                for(i = 1; i <= rows; i++) { for(space="1;" space <="rows-i;" space++) printf(" "); for(j="1;" j j++) printf("*"); printf("\n"); } return 0; output : * *** ***** ******* ********* pre>
                    

Explanation of code :

  • This C program will create an equilateral or a full pyramid pattern triangle.
  • Nested loops are used where spaces are printed first, and then the stars.
  • Popular triangle pattern in a C program that will help you understand alignment and symmetry.
  • They are frequently asked in interviews and tests to know about your loop. Logic.

Option 4: Pattern Program in C for Pascal's Triangle

Program code :

                            #include 

                    int fact(int n) {
                        if(n==0) return 1;
                        else return n*fact(n-1);
                    }

                    int main() {
                        int i, j, rows = 5;
                        for(i = 0; i < rows; i++) {
                            for(j = 0; j <= 1 2 3 4 6 rows-i-1; j++) printf(" "); for(j="0;" j <="i;" printf("%d ", fact(i) (fact(j)*fact(i-j))); printf("\n"); } return 0; output : pre>
                    

Explanation of code :

  • A Pascal triangle using factorial. logoc is printed in this type of C program.
  • Based on combinations, each number is calculated like a binomial coefficient.
  • Your mathematical logic and recursion in programming will be strengthened by practicing this triangle pattern code.
  • This Pascal. The triangle pattern is common in mathematics and programming.

Option 5: C Pattern Program for Hollow Triangle

Program code :

                            #include 

                    int main() {
                        int i, j, rows = 5;
                        for(i = 1; i <= 1 rows; i++) { for(j="i;" j < j++) printf(" "); if(i="=" rows || (2*i-1)) printf("*"); else } printf("\n"); return 0; output : * ********* pre>
                    

Explanation of code :

  • Here you will learn how to create a hollow equilateral triangle.
  • Using conditional statements, stars are printed at the edges of triangles within loops.
  • Such triangle patterns will improve your understanding of nested loops and conditionals, too.

Option 6: Pattern in C Programming for Number Triangle

Program code :

                        #include 

                        int main() {
                            int i, j, rows = 5;
                            for(i = 1; i <= 1 2 3 4 5 rows; i++) { for(j="1;" j <="i;" j++) printf("%d ", j); } printf("\n"); return 0; output : pre>
                    

Explanation of code :

  • This easy triangle pattern program in the C language just demonstrates printing patterns sequentially in each of the rows.
  • Such of number pattern will strengthen looping logic and also numeric control.
  • This kind of triangle pattern is quite common in academic exams
  • This excellent practice for beginners is good for learning nested loops and number manipulation.

Option 7: C Pattern Program for Alphabet Triangle

Program code :

                    #include 

                    int main() {
                        int i, j, rows = 5;
                        char ch;
                        for(i = 1; i <= rows; i++) { ch="A" ; for(j="1;" j <="i;" j++) printf("%c ", ch++); } printf("\n"); return 0; output : a b c d e pre>
                    

Explanation of code :

  • This interesting triangle pattern in C shows an alphabet pattern
  • Character increments (ASCII values) are used to print the alphabet in sequence.
  • Practicing this pattern will help in clearly understanding character manipulation in C.
  • Such a pattern is useful for beginners to master character handling and also get nested loops effectively.

Option 8: C Pattern Program for Inverted Full Pyramid

Program code :

                        #include 

                        int main() {
                            int rows = 5, i, j, space;
                            for (i = rows; i >= 1; i--) {
                                for (space = 1; space <= rows - i; space++) printf(" "); for (j="1;" j <="2" * i 1; j++) printf("*"); printf("\n"); } return 0; output : ********* ******* ***** *** pre>
                    

Explanation of code :

  • This type of pyramid pattern in C programming will print an inverted pyramid of stars
  • number of stars per row will be reduced ultimately, and the initial space will be increased.
  • Loop logic can be understood clearly with this C programming pattern.
  • Quite tested in beginner programming assignments.

Option 9: Pattern Program in C for Half Pyramid

Program code :

                        #include 

                        int main() {
                            int rows = 5, i, j;
                            for (i = 1; i <= rows; i++) { for (j="1;" j <="i;" j++) printf("*"); printf("\n"); } return 0; output : * ** *** **** ***** pre>
                    

Explanation of code :

  • This half pyramid pattern in C programming is one of the simplest patterns.
  • Stars will be printed in increasing order in each row using nested loops.
  • Such a simple pyramid pattern in C programming will form the basic understanding required to understand advanced patterns.
  • Beginners will often practice this pattern first when they are learning nested loop patterns.

Option 13: Solid Diamond Pattern Printing in C

Program code :

                            #include 

                    int main() {
                        int rows = 5, i, j, space;

                        // Upper half
                        for(i = 1; i <= rows; i++) { for(space="1;" space <="rows" - i; space++) printf(" "); for(j="1;" j 1; j++) printf("*"); printf("\n"); } lower half for(i="rows" i>= 1; i--) {
                            for(space = 1; space <= rows - i; space++) printf(" "); for(j="1;" j <="2*i" 1; j++) printf("*"); printf("\n"); } return 0; output : * *** ***** ******* ********* pre>
                    

Explanation of code :

  • The diamond pattern program in the C language will comprise two pyramids.
  • One right and one inverted are included in this.
  • Symmetry and spacing logic are seen here using nested loops.
  • This pattern printing in the C language is useful in strengthening loops. Logic is often asked in programming exams.to test logic.

Real-world problem and program :

Program code :

                            #include 
                int main() {
                    int i, j, space, n = 5;

                    // Upper half
                    for(i = n; i >= 1; i--) {
                        for(space = 0; space < n - i; space++)
                            printf(" ");
                        for(j = 1; j <= (2 * i - 1); j++) printf("*"); printf("\n"); } lower half for(i="2;" <="n;" i++) { for(space="0;" space n i; space++) printf(" "); for(j="1;" j return 0; output : ********* ******* ***** *** pre>
                    

Concentric square star pattern

Program code :

                          #include 
                    int main() {
                        int n = 7;  // Change to any odd number >=3
                        int i, j, min;

                        for (i = 0; i < n; i++) {
                            for (j = 0; j < n; j++) {
                                min = i < j ? i : j;
                                min = min < n - i ? min : n - i - 1;
                                min = min < n - j - 1 ? min : n - j - 1;

                                if (min % 2 == 0)
                                    printf("*");
                                else
                                    printf(" ");
                            }
                            printf("\n");
                        }

                        return 0;
                    }

                    Output ( For n = 7 )

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

                       

Conclusion (150 words)

Star pattern programs in C are more than just beginner exercises—they build a strong foundation in logic, loops, conditionals, and spatial reasoning. Through complex patterns like the concentric square design, learners gain exposure to real-world applications such as UI design layouts, radar systems, and data layer traversal in matrix operations. These programs sharpen problem-solving skills and improve code optimization techniques.

Additionally, patterns help in mastering nested loops, coordinate mapping, and creative algorithm design, which are essential in technical interviews and competitive coding. Real-life relevance makes these patterns not only fun but also practical learning tools. Whether you're preparing for exams or cracking coding rounds, mastering star patterns equips you with a structured thought process to tackle larger programming challenges. As you progress to more intricate patterns and algorithms, you'll appreciate how these visual, structured programs lay the groundwork for advanced logic building and software development. Keep practicing and experimenting!

Enroll in a C programming course in Noida to get detailed training information and knowledge about these trending patterns. You can easily crack your dream job with the help of that.

Placed Students

Our Clients

Partners

Uncodemy Learning Platform

Uncodemy Free Premium Features

Popular Courses