Advertisement
Lisaveta777

Triangles with gap

Nov 3rd, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.64 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define WIDE 9
  4. #define HIGH 5
  5. //to do this for obshii case, with SIZE and GAP, even SIZE, vertical GAP, horis GAP
  6. //columns_gap, rows_gap
  7.  
  8. //this one is really easy now to change into summarasing array elements in
  9. //particular triangle are of array
  10.  
  11. //seems that HIGH and WIDE was bad name choice even for particular case, have
  12. //to check it - how fast will i rewrite this programm with different var names
  13. int main()
  14. {
  15.    int i,j,arr[HIGH][WIDE];
  16.    for(i=0;i<HIGH;i++)//populate&print array
  17.    {
  18.        for(j=0;j<WIDE;j++)
  19.        {
  20.            arr[i][j] = WIDE*i+j;
  21.            printf("%4d",arr[i][j]);
  22.        }
  23.        printf("\n");
  24.    }
  25.    for(i=0;i<HIGH;i++)//1
  26.    {
  27.        for(j=0;j<WIDE;j++)//in array formula(limits for j) will go here!!!
  28.        {
  29.            printf("%c",(j>=(WIDE-HIGH)/2&&j<=(WIDE-HIGH)/2+i)?'*':'-');//1 star
  30.        }
  31.        printf("\n");
  32.  
  33.    }
  34.    for(i=0;i<HIGH;i++)//2. only to illustrate, which area I work with
  35.    {
  36.        for(j=0;j<WIDE;j++)
  37.        {
  38.            printf("%c",(j>=(WIDE-HIGH)/2&&j<(WIDE-HIGH/2)-i)?'*':'-');//10 stars+0 space
  39.        }
  40.        printf("\n");
  41.  
  42.    }
  43.    for(i=0;i<HIGH;i++)//3.only to illustrate, which area I work with
  44.    {
  45.        for(j=0;j<WIDE;j++)
  46.        {
  47.            printf("%c",(j>=(WIDE+HIGH)/2-i-1&&j<WIDE-HIGH/2)?'*':'-');//9 spaces
  48.        }
  49.        printf("\n");
  50.  
  51.    }
  52.    for(i=0;i<HIGH;i++)//only to illustrate, which area I work with
  53.    {
  54.        for(j=0;j<WIDE;j++)
  55.        {
  56.            printf("%c",(j>=(WIDE-HIGH)/2+i&&j<WIDE-HIGH/2)?'*':'-');//0 space+10 stars
  57.        }
  58.        printf("\n");
  59.  
  60.    }
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement