Main diagonal and secondary diagonal of a matrix

Nicki_5595 Posted messages 5 Status Member -  
Nicki_5595 Posted messages 5 Status Member -
Bonjour, j'ai beau chercher de l'aide alors ceci est mon dernier espoir, pour solliciter votre aide Je vous présente mon bout de code pour la diagonale principale parce que j'aimerais avoir celle qui détermine la diagonale secondaire
déjà merci pour votre aide...

#include<stdio.h> #include<stdlib.h> main(){ int l,c,i,j; int mat1[50][50],vec1[50],vec2[50]; printf("Entrer le nombre de ligne de la matrice: "); scanf("%d",&l); printf("Entrer le nombre de colonne de la matrice: "); scanf("%d",&c); // creation matrice 1 for(i=0;i<l;i++){ for(j=0;j<c;j++){ printf("entrer la %d ligne et la %d colonne de la matrice 1: ",(i+1),(j+1)); scanf("%d",&mat1[i][j]); } } //affiche matrice 1 printf("\nla matrice 1 est:\n"); for(i=0;i<l;i++){ for(j=0;j<c;j++){ printf("%d\t",mat1[i][j]); } printf("\n"); } // creation diagonale principale for(i=0;i<l;i++){ vec1[i]=mat1[i][i]; } // affiche diagonale principale printf(" \n Diagonale principale est : \n"); for(i=0;i<l;i++){ printf("%d\t",vec1[i]); } // creation diagonale secondaire for(i=0;i<l;i++){ vec2[i]=mat1[i][c-i-1]; } //affiche diagonale secondaire printf(" \n Diagonale secondaire est : \n"); for(i=0;i<l;i++){ printf("%d\t",vec2[i]); } }


Configuration: Windows / Chrome 87.0.4280.66

3 answers

  1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassador 1 588
     
    Hello,
    what is the difference between these two diagonals?
    did you write this code for the main diagonal? if so, I think you will quickly find out how to do it for the secondary diagonal.
    0
    1. Nicki_5595 Posted messages 5 Status Member
       
      I think a lot, yet I haven't found anything in my reflections
      so I would be delighted to have your help on that.
      0
      1. Nicki_5595 Posted messages 5 Status Member > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
         
        I’ve thought it over, but I’ll take some more time, thank you for the info.
        And as soon as I have the answer, you will be informed.
        0