Program to print triangle or pyramid (▲) Pattern:3. | Using C language| C Program series 24|
👨💻Program to print triangle or pyramid (▲) Pattern:3.
Code 1 :
For a FIXED number of LINENS:
/*
Pattern 3
*
* *
* * *
* * * *
* * * * *
*/
#include<stdio.h>
main()
{
printf("Pyramid Pattern\n\n");
int i,j,k;
//i for row
//j for colomn
for(i=1;i<=5;i++)
{
for(k=4;k>=i;k--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
}
The Output of code 1:
👨💻Program to print triangle or pyramid (▲) Pattern:3 for n number of lines.
Code 2 :
For n number of LINENS:
/*
Program to print triangle Pattern:2 for n number of lines.
For Example:n=6
*
* *
* * *
* * * *
* * * * *
* * * * * *
*/
#include<stdio.h>
main()
{
printf("Program to print triangle or pyramid Pattern:3 for n number of lines.\n\n");
int i,j,k,n;
// n for number
// i for row
// j for column to print '*'
// k for column to print ' '(space)
printf("Enter the number:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=(n-1);k>=i;k--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("* ");
}
printf("\n");
}
}
The output of Code 2:
Comments
Post a Comment