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
- //hate this mess!
- //i have to learn properly pass 2Darray as an argument, and use prototype on top of main(), and function definition
- //at the bottom of main()
- void pr_stars(int,int,int,int,int,int);//top_gap,left_gap,HIGH,WIDE,SIZE,formula clue
- void pop_arr(int a[HIGH][WIDE],int s )
- {
- int i,j;
- for(i=0;i<HIGH;i++)
- {
- for(j=0;j<WIDE;j++)
- {
- a[i][j]= 2*(WIDE*i+j);
- }
- }
- }
- void pr_arr(int a[HIGH][WIDE],int s )
- {
- int i,j;
- for(i=0;i<HIGH;i++)
- {
- for(j=0;j<WIDE;j++)
- {
- printf("%4d",a[i][j]);
- }
- printf("\n");
- }
- }
- void sum_arr(int a[HIGH][WIDE],int s,int t,int l, int clue)//
- {
- int i,j,start,finish,sum=0;
- for(i= t;i< t+s ;i++)//1 arr
- {
- switch(clue)
- {
- case 1: start = l;finish=l-t+i;break;
- case 2: start = l;finish = l+t+s-i;break;
- case 3: start = l+t+s-i-1;finish=l+s;break;
- case 4: start = l-t+i;finish=l+s;break;
- }
- for(j=start;j<finish;j++)
- {
- printf("%4d",a[i][j]);
- sum+=a[i][j];
- }
- printf("\n");
- }
- printf("equals to %d\n",sum);
- }
- int main()
- {
- int i,j,arr[HIGH][WIDE],arr2[HIGH][WIDE],top_gap,left_gap,sum=0;
- printf("Enter rows_gap,cols_gap: ");
- scanf("%d %d",&top_gap,&left_gap);
- pop_arr(arr,SIZE);
- pr_arr(arr,SIZE);
- pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,1);//print triangles in rectangle
- pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,2);
- pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,3);
- pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,4);
- sum_arr(arr,SIZE,top_gap,left_gap,1);//summarise part of array
- sum_arr(arr,SIZE,top_gap,left_gap,2);
- sum_arr(arr,SIZE,top_gap,left_gap,3);
- sum_arr(arr,SIZE,top_gap,left_gap,4);
- return 0;
- }
- void pr_stars(int t,int l,int h,int w,int s ,int clue)
- {
- int i,j,start,finish;
- for(i=0;i<h;i++)//1 1 star + 9 spaces
- {
- if(i<t||i>=t+s)
- {
- for(j=0;j<w;j++)
- printf("+");
- printf("\n");
- }
- else
- {
- for(j=0;j<w;j++)
- {
- switch(clue)
- {
- case 1: start = l;finish = l-t+i+1;break;
- case 2: start = l;finish = l+t+s-i;break;
- case 3: start = l+t+s-i-1;finish = l+s;break;
- case 4: start = l-t+i; finish = l+s;break;
- }
- printf("%c",(j>=start&&j<finish)?'*':'-');
- }
- printf("\n");
- }//end of else
- }//enf of for i
- }
Add Comment
Please, Sign In to add comment