Advika bought a cadbaury gems pocket for his friends. She opened the pocket and arranged the gems colour wise. After finishing the arrangement it looked like a matrix.
Now She wanted to calculate sum of boundary elements of a matrix.
If you help Advika, she will share chocolates with you.
Input:
The first input has two numbers r and c respectively.
Then r rows with c columns follow
Output:
print the single value representing sum of boundary elements of a Matrix.
#include <stdio.h> int main() { int r,c; int arr[100][100],sum = 0,i,j; scanf("%d %d",&r,&c); for(i = 0;i < r;i++){ for(j=0;j < c;j++){ scanf("%d",&arr[i][j]); } } for(i=0;i<r;i++){ for(j=0;j<c;j++){ if(i==0 || j==0 || i==r-1 || j==c-1){ sum+=arr[i][j]; } } } //printf("Sum: "); printf("%d",sum); return 0; }
INPUT_1:
3 3
1 2 3
4 5 6
7 8 9
OUTPUT:
40
INPUT_2:
2 3
1 2 3
4 5 4
OUTPUT:
19
INPUT_3:
3 3
100 200 300
50 26 80
600 120 45
OUTPUT:
Sum: 1495
ILLUSTRATION:
Morae! Q
- Find a triplet such that triplet is minimum of all the triplets.
- Rearrange characters in a string such that no two adjacent are same.
- Return the coordinates of all cells in matrix sorted by their distance.
- Function to verify the ISBN number from the book.
- Find out the absolute difference of values of two array integers.
- Rotate the array in the right direction by K steps.
- Find the sequence of moves that wins the game, collect exactly G coins!.
- Calculate the sum of boundary elements of a matrix.
- Find the total number of ways to reach the tree house.
- Compute profit and loss of a product.
- Find the total expense of purchased items.
- Determine the maximum sequence weight.
- Find the person’s birth year is a leap year or not.
- Find the inner rating with the displayed rating.
- Find if angles are valid to form a triangle.
- Find out the winner of the game from the given statistics.
- Verify the tag to determine if one needs to arrest or allow the vehicle.
- Find the largest hexadecimal number.
- Group up all anagrams together from given words.
- Return all anagrams from the given words.