Код:
![Выделить весь код](images/misc/selectcode.png)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int const x2=78, y2=30, pitch=x2+1, area_size=pitch*y2;
int x=1, normal=(x2-y2)/2;
char *img = malloc(area_size), *last=img+area_size-pitch, *row=last;
memset(img, ' ', area_size);
for(;;) {
if (0<normal) {
normal-=y2;
img[x]=last[x]=row[x]='x';
if (x<x2) { ++x; }
}
else {
normal+=x2;
row[0]=row[pitch-2]='x';
row[pitch-1]='\n';
if ((row-=pitch)<img) break;
}
}
fwrite(img, y2, pitch, stdout);
free(img);
}
Код:
![Выделить весь код](images/misc/selectcode.png)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
int const x2=78, y2=30, pitch=x2+1, area_size=pitch*y2;
char *img = malloc(area_size);
unsigned const dx=x2-2, dy=y2-2;
int const width = (x2+y2)/2;
unsigned x, y;
for(y=0; y<y2; ++y) {
img[(y+1)*pitch-1] = '\n';
for(x=0; x<x2; ++x) {
img[y*pitch+x] =
x - 1 < dx && y - 1 < dy &&
width < (x-dx)*dy + y*dx ? ' ' : 'x';
}
}
fwrite(img, y2, pitch, stdout);
free(img);
}