Star Pattern in c Programming language | Print star pattern in c language


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.



techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490



1. C program to print right Angled triangle star pattern

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#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

*

**

***

****

*****

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#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

*****

****

***

**

*

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#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

*****

*****

*****

*****

*****

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#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

*

**

* *

* *

* * * * *

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#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

*

**

* *

* *

* * * * *

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#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

*

***

*****

*******

*********

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#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

*********

*******

*****

***

*

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#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

*

**

**

**

*********

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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

*********

**

**

**

*

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#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

*

**

***

****

*****

****

***

**

*

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#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

*

***

*****

*******

*********

*******

*****

***

*

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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

*

* *

*    *

*       *

*        *

*       *

*    *

* *

*

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#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;
}





Related Topics






Popular Posts