program of sum of diganal matrix in c lang.?
What is the logic of sum of diganal matrix in the programming in c?
int sumDiag(int* matrix, int rows, int cols)
{
int sum = 0;
int size = rows %26gt; cols ? cols : rows; //choose the smaller one
for(int i = 0 ;i %26lt; size; i++)
sum+= *(*(matrix +i) + i); //add each diagonal item
return sum;
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment