the diagonal goes depending to the row and colume that the user enter
it can be also : row=3 col=0
the diagonal is 4
i kind messed up with the loop
this what i write so far
int r_c_sum(int ar[N][N],int row,int col){
int i,j,sum=0;
if(row==0)
for(i=0;i<=N;i++)
sum+=ar[row+1][col+1];
sum+=ar[row][col];
return sum;
}
you're not actually incrementing row and column. You're just adding an offset so it ends up adding the same row and col each iteration.
Say the row = 1 and col = 0.
It's going to add 7, three times, then add 4.
You need to actually increment row and col using the ++ operator.
Also, you need to bounds check the row and col variables, not iterate over the dimension of the matrix, else you'll risk going out of bounds.
row and col start the place where you start summing. If you start row and col at 2 each and iterate over the dimension of N, you'll be trying to sum values that are outside of the matrix.