Advertisement
Lisaveta777

Part array sum(top)

Nov 1st, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3. #define SIZE 5
  4.  
  5. //https://otvet.mail.ru/question/211269192 – this time 10.30 to 1.30(as in clock)
  6. //sum for part of array - top of it!
  7.  
  8. void pop_arr(int *,int);
  9. void pr_arr(int *,int);
  10.  
  11. int main()
  12. {
  13.     int i,j,arr[SIZE][SIZE],total,step = 0;
  14.     total = 0;
  15.  
  16.     for(i=0;i<SIZE;i++)
  17.     {
  18.         for(j=0;j<SIZE;j++)
  19.         {
  20.             arr[i][j]= SIZE*i+j;
  21.             printf("%d\t",arr[i][j]);
  22.         }
  23.         printf("\n");
  24.     }
  25.  
  26.     for(i = 0;i<=SIZE/2+1;i++)
  27.     {
  28.         for(j = 0;j<SIZE;j++)
  29.         {
  30.             if(j>=step&&j<SIZE-step)
  31.                 {total+=arr[i][j];printf("%d\t",arr[i][j]);}
  32.         }
  33.         printf("\n");
  34.         step++;
  35.     }
  36.     printf("total is %d now\n",total);
  37.  
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement