Created
October 5, 2016 04:33
-
-
Save towkir/44a6e4bc870670821c9b6938cfd37e0a to your computer and use it in GitHub Desktop.
This C program takes an odd number (N) as input and returns a pyramid of N row
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() { | |
int rows, i, j, k, spaces, stars; | |
printf("Enter rows for your pyramid:\n"); | |
scanf("%d", &rows); | |
spaces = rows -1; | |
stars = 1; | |
if (rows % 2 > 0 && rows < 30){ | |
printf("Your pyramid should look like this:\n"); | |
for (i=0; i<rows; i++){ | |
for (j=0; j<spaces; j++){ | |
printf(" "); | |
} | |
spaces--; | |
for (k=0; k<stars; k++){ | |
printf("*"); | |
} | |
stars += 2; | |
printf("\n"); | |
} | |
} else { | |
printf("please enter odd numbers less than 30 only\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment