0
I’m having a hard time creating a printf that depends on the input. I want you to print depending on how many numbers you have diagonally in a matrix and display those numbers. EXAMPLE:
You must print the values used for the calculation of the trace and the value of the trace itself according to the following model:
tr(A) = (1.00) + (5.00) + (9.00) = 15.00IN THE CASE THIS IS A 3X3 MATRIX, BUT IT WILL NOT ALWAYS BE
That’s what I’ve done so far:
#include <stdio.h>
int main() {
int n=0, soma=0, total=0;
scanf("%d", &n);
int matriz[n][n];
for(int i=0; i<n; i++){
  for(int j=0; j<n; j++){
  
    scanf("%d", &matriz[i][j]);
    if(i==j){
    total=total+matriz[i][j];
    
    printf("tr(A) = (%d) +....n  = %d", matriz[n][n], total);
    }
  }
}
  
   return 0;
}
If you have a square matrix n x n then the diagonals, both primary and secondary, will have n elements. To print this variable amount of elements use a loop. (I didn’t understand your example, you didn’t show an array)
– anonimo