Advertisement
Shailrshah

Awkward Loop Design

Mar 11th, 2014
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.41 KB | None | 0 0
  1. #include <stdio.h>
  2. #define N 5
  3. int main()
  4. {
  5.     int i, j, space;
  6.     int toPrint = 1;
  7.     for(i = 0; i < N; i++){
  8.         space = N/2+1;
  9.         if(i%2)space = space-i;
  10.         else space = space-i+1;
  11.         for(j = 0; j < space; j++) printf(" ");
  12.         for(j = 0; j <= i; j++){
  13.             printf("%d ", toPrint);
  14.             toPrint = toPrint > 0 ? 0 : 1;
  15.         }
  16.         printf("\n");
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement