sicily 6572. partial sum

Description
Given a two-dimention array whose elements are all integers,please calculate the sum of its elements,ignoring thoes who sit at the edge of the array.
For example,given a 7 * 4 array,you should calculate the sum of the 5 * 2 elements.

Input
 Input contains many test cases.For each case,the first line is two integer n and m (0 < n,m <= 100),seperated by space,standing for n * m array.The following n line is the array's elements,separted by space.The input is end by 0 0.

Output
 For each test cases,ouput the sum in a line.

大水题……只要改累加的起点和终点就好了

View Code
 1 #include<stdio.h>
 2 #define MAX 101
 3 int partialSum( int matrix[][MAX], int row, int column );
 4 
 5 int main()
 6 {
 7     int matrix[MAX][MAX] = {0};
 8     int i, j;
 9     int row, column;
10     
11     while ( scanf( "%d %d", &row, &column ) && row != 0 )
12     {   
13         for ( i = 0; i < row; i++ )
14         {
15             for ( j = 0; j < column; j++ )
16             {
17                 scanf( "%d", &matrix[i][j] );
18             } 
19         }
20         
21         printf( "%d\n", partialSum( matrix, row, column ) );
22         
23     }
24     return 0;
25 }
26 
27 int partialSum( int matrix[][MAX], int row, int column )
28 {
29     int i, j;
30     int sum = 0;
31     
32     for ( i = 1; i < row - 1; i++ )
33     {
34         for ( j = 1; j < column - 1; j++ )
35         {
36             sum = sum + matrix[i][j];
37         } 
38     }
39     
40     return sum; 
41 }
原文地址:https://www.cnblogs.com/joyeecheung/p/2813521.html