Created
October 30, 2016 01:46
-
-
Save rich-97/872f8d4fba45e7024ddd93033f5b5fbc to your computer and use it in GitHub Desktop.
Program that generate a pyramid with asterisks
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 row; | |
int column; | |
int count_char; | |
int length_rows; | |
int index_columns; | |
int length_columns; | |
void print (int count) { | |
for (int i = 0; i < count; i++) | |
printf("*"); | |
} | |
int point_column (int length_columns) { | |
return (length_columns - 1) / 2; | |
} | |
int main () { | |
printf("Enter the total of rows: "); scanf("%d", &length_rows); | |
printf("Enter the total of columns: "); scanf("%d", &length_columns); | |
if (length_columns % 2 == 0) | |
length_columns -= 1; | |
index_columns = point_column(length_columns); | |
for (row = 0; row < length_rows; row++) { | |
for (column = 0; column < length_columns; column++) { | |
if (column == index_columns) { | |
if (row == 0) | |
count_char = row + 1; | |
else | |
count_char += 2; | |
print(count_char); | |
index_columns--; | |
} | |
printf(" "); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
rows must be entered with an odd number to successfully build the pyramid if the program makes it an odd number.