Input Format:
The first line contains R and C separated by a space..
Next R lines contain C values each, with the values separated by a space.
The first line contains R and C separated by a space..
Next R lines contain C values each, with the values separated by a space.
Output Format:
The first line contains S.
The first line contains S.
Boundary Conditions:
2 <= R, C <= 100
1 <= Matrix Cell Value <= 1000
2 <= R, C <= 100
1 <= Matrix Cell Value <= 1000
Example Input/Output 1:
Input:
5 3
1 2 3
4 5 6
7 8 9
5 5 5
2 2 2
Input:
5 3
1 2 3
4 5 6
7 8 9
5 5 5
2 2 2
Output:
48
48
Example Input/Output 2:
Input:
3 3
100 200 300
400 500 600
700 800 900
Input:
3 3
100 200 300
400 500 600
700 800 900
Output:
4000
4000
C code:
#include<stdio.h>
#include <stdlib.h>
int main()
{
int r,c;
scanf("%d%d",&r,&c);
int t,s=0;
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
{
scanf("%d",&t);
if(i==0||i==r-1||j==0||j==c-1)
s+=t;
}
printf("%d",s);
}