Created
October 1, 2018 22:53
-
-
Save waggertron/3e05c9893b8060219e41427e3201ff16 to your computer and use it in GitHub Desktop.
build pyramid one loop construction
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> | |
#include <stdlib.h> | |
#include <string.h> | |
char * char_repeat( int n, char c ) { | |
char * dest = malloc(n+2); | |
memset(dest, c, n); | |
dest[n] = '\n'; | |
dest[n + 1] = '\0'; | |
return dest; | |
} | |
int main() | |
{ | |
int i, j, rows; | |
char character = '*'; | |
printf("Enter number of rows: "); | |
scanf("%d",&rows); | |
char arr[rows * 2 -1][rows + 2]; | |
for(i = 0; i < rows; ++i) | |
{ | |
strcpy(arr[i], char_repeat(rows - i, character)); | |
strcpy(arr[i+rows], char_repeat(i + 1, character)); | |
} | |
for (j=0; j < rows * 2; j++) { | |
printf("%s", arr[j]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment