uni

University stuff
git clone git://git.margiolis.net/uni.git
Log | Files | Refs | README | LICENSE

shapes.c (1430B)


      1 #include <stdio.h>
      2 
      3 int main(int argc, char *argv[])
      4 {
      5     int row, rowsTotal, col, colsTotal, spaces;
      6     
      7     printf("How many rows?: ");
      8     scanf("%d", &rowsTotal);
      9     colsTotal = rowsTotal;
     10 
     11     printf("\n");
     12     
     13     for (row = 0; row < rowsTotal; row++)
     14     {
     15         printf("*\n");
     16         for (col = row+1; col > 0; col--)
     17         {
     18             if (row+1 < colsTotal)
     19                 printf("*");
     20         }
     21     }
     22 
     23     printf("\n");
     24 
     25     for (row = 0; row < rowsTotal; row++)
     26     {
     27         for (col = row+1; col < colsTotal; col++)
     28             printf(" ");
     29         
     30         for (col = 0; col <= row; col++)
     31             printf("*");
     32 
     33         printf("\n");
     34     }
     35 
     36     printf("\n");
     37 
     38     spaces = rowsTotal;
     39     for (row = 1; row <= rowsTotal; row++)
     40     {
     41         for (col = 1; col < spaces; col++)
     42             printf(" ");
     43         
     44         for (col = 0; col < 2*row - 1; col++)
     45             printf("*");
     46         
     47         printf("\n");
     48         spaces--;
     49     }
     50 
     51     printf("\n");
     52 
     53     for (row = 1; row <= rowsTotal; row++)
     54     {
     55         for (col = 1; col <= colsTotal; col++)
     56         {
     57             if (row == 1 || row == rowsTotal || col == 1 || col == colsTotal)
     58                 printf("*");                
     59             else if (row == col || col == (rowsTotal - row + 1))
     60                 printf("ยท");
     61             else
     62                 printf(" ");
     63         }
     64 
     65         printf("\n");
     66     }
     67 
     68     printf("\n");
     69 
     70     return 0;
     71 }