Skip to content

Instantly share code, notes, and snippets.

@rich-97
Created October 30, 2016 01:46
Show Gist options
  • Save rich-97/872f8d4fba45e7024ddd93033f5b5fbc to your computer and use it in GitHub Desktop.
Save rich-97/872f8d4fba45e7024ddd93033f5b5fbc to your computer and use it in GitHub Desktop.
Program that generate a pyramid with asterisks
#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;
}
@rich-97
Copy link
Author

rich-97 commented Oct 30, 2016

rows must be entered with an odd number to successfully build the pyramid if the program makes it an odd number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment