Advertisement
alfps

snowflake

Sep 11th, 2020
1,056
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <stdlib.h>     // abs
  2. #include <iomanip>
  3. #include <iostream>
  4. using   std::setw,
  5.         std::cout, std::endl;
  6.  
  7. auto main()
  8.     -> int
  9. {
  10.     const int n = 4;
  11.     const int w = 1 << n;
  12.     for( int y = 0; y < 2*w - 1; ++y ) {
  13.         const int cw = w - 1;
  14.         cout << setw( abs( cw - y ) ) << "";
  15.         const int cy = cw - abs( cw - y );
  16.         for( int x = 0; x < w + y; ++x ) {
  17.             const int tx = (x < cy? x : x < w? w - 1 - x : x + 1 - w);
  18.             const int ty = (x < cy? cy : x < w? w - 1 - cy : cy);
  19.             const char ch = (tx & ~ty? ' ' : '@');
  20.             cout << setw( 2 ) << ch;
  21.         }
  22.         cout << endl;
  23.     }
  24. }
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement