This repository has been archived on 2021-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
sys_prog/diamond/diamond.c

36 lines
612 B
C
Raw Normal View History

2019-09-23 20:24:37 +00:00
#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]));
}