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/archive/2012/12/11/2813521.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值