Lisaveta777

Messy

Nov 4th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define WIDE 15
  4. #define HIGH 9
  5. #define SIZE 5
  6.  
  7. //hate this mess!
  8. //i have to learn properly pass 2Darray as an argument, and use prototype on top of main(), and function definition
  9. //at the bottom of main()
  10. void pr_stars(int,int,int,int,int,int);//top_gap,left_gap,HIGH,WIDE,SIZE,formula clue
  11. void pop_arr(int a[HIGH][WIDE],int s )
  12. {
  13.     int i,j;
  14.     for(i=0;i<HIGH;i++)
  15.     {
  16.         for(j=0;j<WIDE;j++)
  17.         {
  18.             a[i][j]= 2*(WIDE*i+j);
  19.         }
  20.     }
  21. }
  22. void pr_arr(int a[HIGH][WIDE],int s )
  23. {
  24.     int i,j;
  25.     for(i=0;i<HIGH;i++)
  26.     {
  27.         for(j=0;j<WIDE;j++)
  28.         {
  29.             printf("%4d",a[i][j]);
  30.         }
  31.         printf("\n");
  32.     }
  33. }
  34. void sum_arr(int a[HIGH][WIDE],int s,int t,int l, int clue)//
  35. {
  36.     int i,j,start,finish,sum=0;
  37.     for(i= t;i< t+s ;i++)//1 arr
  38.     {
  39.         switch(clue)
  40.         {
  41.             case 1: start = l;finish=l-t+i;break;
  42.             case 2: start = l;finish = l+t+s-i;break;
  43.             case 3: start = l+t+s-i-1;finish=l+s;break;
  44.             case 4: start = l-t+i;finish=l+s;break;
  45.  
  46.         }
  47.        for(j=start;j<finish;j++)
  48.        {
  49.            printf("%4d",a[i][j]);
  50.            sum+=a[i][j];
  51.        }
  52.        printf("\n");
  53.     }
  54.  
  55.  
  56.     printf("equals to %d\n",sum);
  57. }
  58.  
  59. int main()
  60. {
  61.    int i,j,arr[HIGH][WIDE],arr2[HIGH][WIDE],top_gap,left_gap,sum=0;
  62.    printf("Enter rows_gap,cols_gap: ");
  63.    scanf("%d %d",&top_gap,&left_gap);
  64.    pop_arr(arr,SIZE);
  65.    pr_arr(arr,SIZE);
  66.  
  67.    pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,1);//print triangles in rectangle
  68.    pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,2);
  69.    pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,3);
  70.    pr_stars(top_gap,left_gap,HIGH,WIDE,SIZE,4);
  71.  
  72.    sum_arr(arr,SIZE,top_gap,left_gap,1);//summarise part of array
  73.    sum_arr(arr,SIZE,top_gap,left_gap,2);
  74.    sum_arr(arr,SIZE,top_gap,left_gap,3);
  75.    sum_arr(arr,SIZE,top_gap,left_gap,4);
  76.  
  77.     return 0;
  78. }
  79.  
  80. void pr_stars(int t,int l,int h,int w,int s ,int clue)
  81. {
  82.     int i,j,start,finish;
  83.     for(i=0;i<h;i++)//1  1 star + 9 spaces
  84.    {
  85.        if(i<t||i>=t+s)
  86.             {
  87.                 for(j=0;j<w;j++)
  88.                     printf("+");
  89.                 printf("\n");
  90.             }
  91.        else
  92.         {
  93.             for(j=0;j<w;j++)
  94.             {
  95.                 switch(clue)
  96.                 {
  97.                     case 1: start = l;finish = l-t+i+1;break;
  98.                     case 2: start = l;finish = l+t+s-i;break;
  99.                     case 3: start = l+t+s-i-1;finish = l+s;break;
  100.                     case 4: start = l-t+i; finish = l+s;break;
  101.                 }
  102.                 printf("%c",(j>=start&&j<finish)?'*':'-');
  103.                
  104.             }
  105.         printf("\n");
  106.  
  107.         }//end of else
  108.    }//enf of for i
  109. }
Add Comment
Please, Sign In to add comment