#include <stdio.h>
#define MAX_SIZE 1000
int N, M;
int A[MAX_SIZE] [MAX_SIZE];
int main() {
    int i, j;
    int r0, r1, c0, c1, sum = 0;
    scanf("%d", &N);
    for (i = 0; i < N; i++) {
        for (j = 0; j < N; j++) {
            scanf("%d", &A[i][j]);
        }
    }
    scanf("%d", &M);
    for (i = 0; i < M; i ++) {
        scanf("%d%d%d%d", &r0, &r1, &co, &c1);
        // TODO: compute the sub-matrix sum.
        for (i = r0; i < r1; i++) {
            for (j = c0; j < c1; j++) {
            sum +=A[i][j];
            }
        }
        printf("%d\n", sum);
        sum = 0;
    }
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: