Created
April 25, 2017 07:11
-
-
Save znxkznxk1030/bd64b7773524186452789ace5434805e to your computer and use it in GitHub Desktop.
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> | |
char** arr; | |
void mk_tri(int dis, int x, int y); | |
int main(int argc, char* argv[]) | |
{ | |
int n, size; | |
scanf("%d", &n); | |
size = n * 2 - 1; | |
arr = (char**)malloc(sizeof(char*) * n); | |
for (int i = 0; i < n; i++) | |
{ | |
arr[i] = (char*)malloc(sizeof(char) * size + 2); | |
for (int j = 0; j < size; j++) | |
arr[i][j] = ' '; | |
arr[i][size] = '\n'; | |
arr[i][size + 1] = '\0'; | |
} | |
mk_tri(n, 0, n - 1); | |
for (int i = 0; i < n; i++) { | |
printf(arr[i]); | |
} | |
return 0; | |
} | |
void mk_tri(int dis, int x, int y) | |
{ | |
int half_dis = dis / 2; | |
if (dis == 3) | |
{ | |
arr[y - 2][x + 2] = '*'; | |
arr[y - 1][x + 1] = '*'; | |
arr[y - 1][x + 3] = '*'; | |
for (int i = 0; i < 5; i++) | |
arr[y][x + i] = '*'; | |
} | |
else { | |
mk_tri(half_dis, x, y); | |
mk_tri(half_dis, x + dis, y); | |
mk_tri(half_dis, x + half_dis, y - half_dis); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment