This commit is contained in:
Claudio Maggioni 2019-09-23 22:24:37 +02:00
parent c072df226b
commit ffd992d549

35
diamond/diamond.c Normal file
View file

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
void d_line(unsigned int i, unsigned int n) {
unsigned int j;
for (j = 0; j < n - i; j++)
putchar(' ');
for (j = 0; j < (2*i - 1); j++)
putchar('#');
putchar('\n');
}
void diamond(int n) {
if (n <= 0) {
return;
}
unsigned int i;
for (i = 1; i <= n; i++) {
d_line(i, n);
}
for (i = n-1; i > 0; i--) {
d_line(i, n);
}
}
int main(int argc, char** argv) {
if (argc != 2) {
fprintf(stderr, "Usage: %s [side]\n", argv[0]);
return 1;
}
diamond(atoi(argv[1]));
}