Skip to content

Instantly share code, notes, and snippets.

@znxkznxk1030
Created April 25, 2017 07:11
Show Gist options
  • Save znxkznxk1030/bd64b7773524186452789ace5434805e to your computer and use it in GitHub Desktop.
Save znxkznxk1030/bd64b7773524186452789ace5434805e to your computer and use it in GitHub Desktop.
#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