digit-octagon.c 613 B

123456789101112131415161718192021222324252627282930
  1. #include <stdio.h>
  2. int main() {
  3. int itr;
  4. int spc = 7;
  5. int mid = 1;
  6. int bdr = 1;
  7. int swt = 0;
  8. for (int x = 0; x < 22; ++x) {
  9. for (itr = 0; itr < spc; ++itr)
  10. printf(" ");
  11. while (bdr < mid)
  12. printf("%d", bdr++);
  13. for (itr = 0; itr < 8; ++itr)
  14. printf("%d", mid);
  15. while (bdr > mid || bdr > 1)
  16. printf("%d", --bdr);
  17. printf("\n");
  18. if (mid < 8 && swt == 0) {
  19. mid++;
  20. spc--;
  21. } else swt++;
  22. if (swt > 7) {
  23. mid--;
  24. spc++;
  25. }
  26. }
  27. }