Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - Find the sum of triangle elements under a 5x5 integer matrix with C language.
Find the sum of triangle elements under a 5x5 integer matrix with C language.
To calculate the sum of all the elements of the lower triangle, you must traverse all the elements of the lower triangle and add the values of all the elements to a variable.

Assume that row represents the current row and col represents the current column. Sum represents the sum of the current elements.

For the line 1, we need to traverse 1 elements.

For line 2, we need to traverse 2 elements.

. . .

For line 5, we need to traverse five elements.

Therefore, the approximate code should be longer than this sample paper:

int? Calculate trigonometric sum (int? matrix[5][5])? {

int? sum? =? 0;

int? Row,? col

Everyone's? Row? =? [0? ~? 4]? {

Everyone's? Cole? =? [0? ~? Row]? {

sum? +=? Matrix [row] [column];

}

}

Return? Sum;

} Just fill in other necessary codes at last!

# Contains? & ltstdio.h & gt

int? getLowerTriangleSum(int? matrix[5][5])? {

int? sum? =? 0;

int? Row,? col

for(row = 0; ? row & lt5; ? row++)? {

for(col = 0; ? Col< line+1; ? col++)? {

sum? +=? Matrix [row] [column];

}

}

Return? Sum;

}

int? main()? {

int? Matrix [5][5]? =? {

{ 1,? 2,? 3,? 4,? 5},

{6,? 7,? 8,? 9,? 10},

{ 1 1,? 12,? 13,? 14,? 15},

{ 16,? 17,? 18,? 19,? 20},

{2 1,? 22,? 23,? 24,? 25}

};

int? sum? =? GetLowerTriangleSum (matrix);

Printf ("lower? Triangle? sum? Yes? Matrix? Is it? %d\n ",sum);

Return? 0;

}