#include <stdio.h>
#include <conio.h>
/*Program to build pyramids in pure c language
With some slight modifications, different types of pyramids can be created.
Numbers can also be used to build pyramids
This program actually prints a diamond with * or numbers but with slight
modifications, a pyramid can also b printed.
*/
int main(int argc, char * argv[]) {
int i, k, n = 1, m;
printf("\nPlease enter the number of lines for the pyramid\n");
printf("You can call it the radious of the pyramid");
printf("Number should be with in 1-30\n");
scanf("%d", & n);
//This loop is used to print two print two pyramids
//one of them will be updisde down to make a diamond.
for (m = 0; m < 2; m++) {
//loop through the number, the user has entered
//loop to traverse through the pyramid
for (i = 1; i <= n; i++) {
//this block print spaces until the pyramid line starts
if (m == 0) { //we are going to print the upper triangle for the diamond
for (k = 1; k <= n - i; k++) { //it will print the spaces equal to the number entered by the user [1]
printf(" ");
}
for (k = 1; k < 2 * i; k++) { //first line will print 1 * only and will increase by 1 each time [2]
//its due to the value of i which is keep increasing 1 by 1
printf("%s", "*");
//printf("%d",i);//uncomment this line and comment above to print the numbers.
}
}
//its the code to print the upside down triangles to complete the diamond.
if (m == 1) {
for (k = 1; k <= i; k++) { //its the reverse of the [1] to print 1 space in the beginning
//and then increase the spaces as the loop counter increases.
printf(" ");
}
for (k = 1; k < (n - i) * 2; k++) { //reverse code for [2], first it will print the * twice the the number which the user entered.
printf("%s", "*");
//printf("%d",i); //uncomment this line and comment above to print the numbers.
}
}
printf("\n");
}
}
system("PAUSE");
return 0;
}