Advertisement
Lisaveta777

Part array sum(down)

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