Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define WIDE 15
- #define HIGH 9
- #define SIZE 5 //this is square size
- //first part - printint triangles - just to illustrate which areas of array
- //are summarise at every instance
- //1. prints triangles of differents directions (with stars), inside rectangles (-)
- //and for gaps uses +. this used as preparation for 2D array
- //2. prints array elements, covered by triangles in first part, summarise them
- //? i think, for j-formula it's better to use the following order: top_gap, left_gap
- //SIZE, i - it have to be standartased, IMHO, and that order seems the most logical
- //plus - have to check all formulas! seem they far from being ideal
- int main()
- {
- int i,j,arr[HIGH][WIDE],top_gap,left_gap,sum=0;
- printf("Enter rows_gap,cols_gap: ");
- scanf("%d %d",&top_gap,&left_gap);
- for(i=0;i<HIGH;i++)//populate&print array
- {
- for(j=0;j<WIDE;j++)
- {
- arr[i][j] = WIDE*i+j;
- printf("%4d",arr[i][j]);
- }
- printf("\n");
- }
- for(i=0;i<HIGH;i++)//1 1 star + 9 spaces
- {
- if(i<top_gap||i>=top_gap+SIZE)
- {
- for(j=0;j<WIDE;j++)
- printf("+");
- printf("\n");
- }
- else
- {
- for(j=0;j<WIDE;j++)
- {
- printf("%c",(j>=left_gap&&j<=left_gap-top_gap+i)?'*':'-');//1 star
- }
- printf("\n");
- }//end of else
- }
- for(i=0;i<HIGH;i++)//2. 10 stars+ 0 spaces
- {
- if(i<top_gap||i>=top_gap+SIZE)
- {
- for(j=0;j<WIDE;j++)
- printf("+");
- printf("\n");
- }
- else
- {
- for(j=0;j<WIDE;j++)
- {
- printf("%c",(j>=left_gap&&j<SIZE+left_gap+top_gap-i)?'*':'-');
- }
- printf("\n");
- }
- }
- for(i=0;i<HIGH;i++)//3. 9 spaces + 1 star
- {
- if(i<top_gap||i>=top_gap+SIZE)
- {
- for(j=0;j<WIDE;j++)
- printf("+");
- printf("\n");
- }
- else
- {
- for(j=0;j<WIDE;j++)
- {
- printf("%c",(j>=left_gap+top_gap+SIZE-i-1&&j<left_gap+SIZE)?'*':'-');
- }
- printf("\n");
- }
- }
- for(i=0;i<HIGH;i++)//4. 0 spaces + 10 stars
- {
- if(i<top_gap||i>=top_gap+SIZE)
- {
- for(j=0;j<WIDE;j++)
- printf("+");
- printf("\n");
- }
- else
- {
- for(j=0;j<WIDE;j++)
- {
- printf("%c",(j>=left_gap-top_gap+i&&j<left_gap+SIZE)?'*':'-');
- }
- printf("\n");
- }
- }
- for(i=top_gap;i<top_gap+SIZE;i++)//1 arr
- {
- //for(j=left_gap;j<=left_gap+i;j++)//before top_gap
- for(j=left_gap;j<=left_gap-top_gap+i;j++)
- printf("%d ",arr[i][j]),sum+=arr[i][j];
- printf("\n");
- }
- printf("equals to %d\n",sum);
- sum=0;//have to be set up to zero for new cycle
- for(i=top_gap;i<top_gap+SIZE;i++)//2 arr
- {
- //for(j=left_gap;j<left_gap+SIZE-i;j++)/before top_gap
- for(j=left_gap;j<SIZE+left_gap+top_gap-i;j++)
- printf("%d ",arr[i][j]),sum+=arr[i][j];
- printf("\n");
- }
- printf("equals to %d\n",sum);
- sum=0;//have to be set up to zero for new cycle
- for(i=top_gap;i<top_gap+SIZE;i++)//3 arr
- {
- //for(j=left_gap+SIZE-i-1;j<left_gap+SIZE;j++)//before top_gap
- for(j=left_gap+top_gap+SIZE-i-1;j<left_gap+SIZE;j++)
- printf("%d ",arr[i][j]),sum+=arr[i][j];
- printf("\n");
- }
- printf("equals to %d\n",sum);
- sum=0;//have to be set up to zero for new cycle
- for(i=top_gap;i<top_gap+SIZE;i++)//4 arr
- {
- //for(j=left_gap+i;j<left_gap+SIZE;j++)//before top_gap
- for(j=left_gap-top_gap+i;j<left_gap+SIZE;j++)
- printf("%d ",arr[i][j]),sum+=arr[i][j];
- printf("\n");
- }
- printf("equals to %d\n",sum);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement