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.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| //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; } }
|
awesome blog love to visit here, for such info visit at: kidsfront.com
ReplyDelete