Pyramid structure in C source code: This program provides you a pyramid formatted output for a given input. This can be a simple code to understand easily. It generates the pyramid shape by using patterns. It is totally based on your “n” number of input. An example program is given below.
CREATE PYRAMID STRUCTURE IN C
Create pyramid structure program in C is used to create the shape of pyramid by given input values. It is using many looping statements and blank spaces to create a pyramid structure exactly.
Pyramid program:
Q: Write a C program to create a pyramid structure using patterns.
//Header files
#include<stdio.h>
#include<conio.h>
void main()
{
//Program variables
int j,i,l,nm,blanks,un;
printf("Enter n value : ");//Display function
scanf("%d",&un);//Getting input function
for(i=1,l=1;i<=un;i++)//Looping statement
{for(blanks=n-1;blanks>=l;blanks--) //Nested loop
printf(" ");
for(j=1,nm=1;j<=l;j++)
{ printf("%d ",nm);
if(j>=((l+1)/2))//Conditional statement
nm--;
else nm++;
}printf("\n");
if(i>=((un+1)/2))
l-=2;
else
l+=2;
}
}
#include<stdio.h>
#include<conio.h>
void main()
{
//Program variables
int j,i,l,nm,blanks,un;
printf("Enter n value : ");//Display function
scanf("%d",&un);//Getting input function
for(i=1,l=1;i<=un;i++)//Looping statement
{for(blanks=n-1;blanks>=l;blanks--) //Nested loop
printf(" ");
for(j=1,nm=1;j<=l;j++)
{ printf("%d ",nm);
if(j>=((l+1)/2))//Conditional statement
nm--;
else nm++;
}printf("\n");
if(i>=((un+1)/2))
l-=2;
else
l+=2;
}
}
No comments:
Post a comment
Note: only a member of this blog may post a comment.