pyramid star pattern in c


1. pyramid star pattern in c

#include <stdio.h>

int main()
{
    int n;
    printf("Enter the size of n");
    scanf("%d",&n);
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<2*n-1;j++)
        {
            if(j>=n-i-1 && j<n+i)
            printf("*");
            else
            printf(" ");
        }
        printf("\n");
    }
    return 0;
}
Output:



pyramid-pattern-c



2. inverted pyramid star pattern in c

#include <stdio.h>

int main()
{
    int n;
    printf("Enter the size of n\n");
    scanf("%d",&n);
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<2*n-1;j++)
        {
            if(j>=i && j<2*n-i-1)
            printf("*");
            else
            printf(" ");
        }
        printf("\n");
    }
    return 0;
}
Output:

inverted-pyramid-pattern-c


3. 180-degree pyramid star pattern in c


#include <stdio.h>

int main()
{
    int n;
    printf("Enter the size of n\n\n");
    scanf("%d",&n);
    
    for(int i=0;i<2*n-1;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(i<n)
            {
                if(j<=i)
                printf("*");
            }
            else
            {
                if(j<2*n-i-1)
                printf("*");
            }
        }
        printf("\n");
    }
    return 0;
}
Output:

180-degree-pyramid-pattern-c


Also, see: