C program to print the right half star pyramid pattern
kw.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
kodingwindow@kw:~$ gcc kw.c
kodingwindow@kw:~$ ./a.out * ** *** **** ***** ****** ******* ******** ********* ********** kodingwindow@kw:~$
C program to print the left half star pyramid pattern
kw.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
kodingwindow@kw:~$ gcc kw.c
kodingwindow@kw:~$ ./a.out * ** *** **** ***** ****** ******* ******** ********* ********** kodingwindow@kw:~$
C program to print the inverted right half star pyramid pattern
kw.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
kodingwindow@kw:~$ gcc kw.c
kodingwindow@kw:~$ ./a.out ********** ********* ******** ******* ****** ***** **** *** ** * kodingwindow@kw:~$
C program to print the inverted left half star pyramid pattern
kw.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
kodingwindow@kw:~$ gcc kw.c
kodingwindow@kw:~$ ./a.out ********** ********* ******** ******* ****** ***** **** *** ** * kodingwindow@kw:~$
Advertisement