2K
Table of Contents
In this C Programming example, you will learn to print half pyramid, pyramid, inverted pyramid triangle.
Pattern 1
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
C Program:
#include<stdio.h>
int main()
{
int n;
printf("Enter the value of N:");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=i;j++)
{
printf("%d",j);
}
for(int z=i-1;z>=1;z--)
{
printf("%d",z);
}
printf("\n");
}
return 0;
}
Pattern 2
A
A B A
A B C B A
A B C D C B A
A B C D E D C B A
C Program:
#include<stdio.h>
int main()
{
int n;
printf("Enter the value of N:");
scanf("%d",&n);
for(int i=65;i<=n+65;i++)
{
for(int j=65;j<=i;j++)
{
printf("%c",j);
}
for(int z=i-1;z>=65;z--)
{
printf("%c",z);
}
printf("\n");
}
return 0;
}
Pattern 3
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
C Program:
#include<stdio.h>
int main()
{
int n;
printf("Enter the value of N:");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int z=n;z>i;z--)
{
printf(" ");
}
for(int j=1;j<=i;j++)
{
printf("%d",j);
}
for(int z=i-1;z>=1;z--)
{
printf("%d",z);
}
printf("\n");
}
return 0;
}
Pattern 4
* * * * 1 * * * *
* * * 2 * 2 * * *
* * 3 * 3 * 3 * *
* 4 * 4 * 4 * 4 *
5 * 5 * 5 * 5 * 5
C Program:
#include<stdio.h>
int main()
{
int n;
printf("Enter the value of N:");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int z=n;z>i;z--)
{
printf("*");
}
for(int j=1;j<=i*2-1;j++)
{
if (j%2==0)
printf("*");
else
printf("%d",i);
}
for(int z=n;z>i;z--)
{
printf("*");
}
printf("\n");
}
return 0;
}
Full Pyramid of *
*
* *
* * *
* * * *
* * * * *
C Program:
#include<stdio.h>
int main()
{
int n;
printf("Enter the value of N:");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for(int z=n;z>i;z--)
{
printf(" ");
}
for(int j=1;j<=i*2-1;j++)
{
if(j%2==0)
printf(" ");
else
printf("*");
}
printf("\n");
}
return 0;
}
Inverted Full Pyramid of *
* * * * *
* * * *
* * *
* *
*
C Program:
#include<stdio.h>
int main()
{
int n;
printf("Enter the value of N:");
scanf("%d",&n);
for(int i=n;i>=1;i--)
{
for(int z=n;z>i;z--)
{
printf(" ");
}
for(int j=1;j<=i*2-1;j++)
{
if(i==n)
{
if(j%2==0)
printf(" ");
else
printf("*");
}
else
{
if (j==1||j==i*2-1)
printf("*");
else
printf(" ");
}
}
printf("\n");
}
return 0;
}
Hollow Full Pyramid of *
*
* *
* *
* *
* * * * *
#include<stdio.h>
int main()
{
int n;
printf("Enter the value of N:");
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
for( int z=n ; z > i ; z--)
{
printf(" ");
}
for( int j=1; j<=i*2-1;j++)
{
if(i == n)
{
if ( j%2 == 0 )
printf(" ");
else
printf("*");
}
else
{
if (j == 1 || j == i*2-1)
printf("*");
else
printf(" ");
}
}
printf("\n");
}
return 0;
}
Hope these C program pattern are help to you , Thank You for reading.
Check Out : Star patterns Program in C