算法1
二维数组求和
C 代码
for (int i = 1; i <= n; i )
for (int j = 1; j <= m; j ++ )
scanf(“%d”, &s[i][j]);
for (int i = 1; i <= n; i ++ )
for (int j = 1; j <= m; j ++ )
s[i][j] += s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];注意+=;已经包含了s[i][j];
算法2
C 代码
for(int i = 1; i <= n; i)
for(int j = 1; j <= m; j)
scanf(“%d”, &a[i][j]);
for(int i = 1; i <= n; i)
for(int j =1; j <= m; j++)
s[i][j] = s[i][j - 1] + s[i - 1][j] -s[i-1][j- 1] + a[i][j];新定义了一个数组a和求和素组s