SpaceCreator

Spiral

Sep 14th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main() {
  4.     int width = 0;
  5.     scanf("%i", &width);
  6.     int upper = width / 2;
  7.     int lower = 0;
  8.     if (width % 2 > 0) {
  9.         lower = upper;
  10.     } else {
  11.         lower = upper - 1;
  12.     }
  13.  
  14.     for (int i = 0; i < upper; ++ i) {
  15.         for (int j = 0; j < i; ++ j) {
  16.             printf("| ");
  17.         }
  18.         printf("%c ", 218);
  19.         for (int j = 0; j < width - 2 - 2 * i; ++ j) {
  20.             printf("%c ", 196);
  21.         }
  22.         printf("%c ", 191);
  23.         for (int j = 0; j < i; ++ j) {
  24.             printf("| ");
  25.         }
  26.         printf("\n");
  27.     }
  28.     width -= 1;
  29.     for (int i = lower - 1; i >= 0; -- i) {
  30.         for (int j = 0; j < i; ++ j) {
  31.             printf("| ");
  32.         }
  33.         printf("%c ", 192);
  34.         for (int j = 0; j < width - 2 - 2 * i; ++ j) {
  35.             printf("%c ", 196);
  36.         }
  37.         printf("%c ", 217);
  38.         for (int j = 0; j < i; ++ j) {
  39.             printf("| ");
  40.         }
  41.         printf("| ");
  42.         printf("\n");
  43.     }
  44.     for (int j = 0; j < width; ++ j) {
  45.         printf("%c ", 196);
  46.     }
  47.     printf("%c ", 217);
  48.  
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment