1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| #include <stdio.h>
#include <stdlib.h>
#define PRINT_MARGIN(LEFT_MARGIN) for(count2=0; count2 < LEFT_MARGIN; ++count2) { printf(" "); }
#define PRINT_ONE_Z_LINE(CHAR, WIDTH) \
for(count2=0; count2 < (WIDTH - 1); ++count2) { \
printf("%c", CHAR); \
} \
\
printf("*\n");
#define PRINT_ONE_ENTIRE_LINE(CHAR, WIDTH, LEFT_MARGIN) \
PRINT_MARGIN(LEFT_MARGIN) \
PRINT_ONE_Z_LINE(CHAR, WIDTH)
void print_z(size_t width, size_t left_margin) {
if (width > 1) {
size_t count1, count2;
PRINT_ONE_ENTIRE_LINE('*', width, left_margin);
for(count1=width; count1 > 0; --count1) {
PRINT_ONE_ENTIRE_LINE(' ', count1, left_margin);
}
PRINT_ONE_ENTIRE_LINE('*', width, left_margin);
}
}
int main (int argc, char** argv)
{
print_z(10, 5);
printf("\n\n");
print_z(3, 5);
printf("\n\n");
print_z(7, 10);
printf("\n\n");
print_z(20, 0);
return EXIT_SUCCESS;
} |
Partager