主な対角要素と副対角要素を交換するコードを記述する必要があります。マトリックスのサイズは実行時に与えられます。
行列の m 値と n 値のサイズが等しくない場合は、指定された行列が正方ではないことを出力します。
主対角要素または副対角要素を交換できるのは正方行列のみです。
特定の行列の対角要素を交換する C プログラムを作成する解決策は次のとおりです-
対角要素を交換するロジック については以下で説明します -
for (i=0;i ログイン後にコピー
以下は、指定された行列の対角要素 を交換するための C プログラムです -
Real-時間デモ#includemain (){ int i,j,m,n,a; static int ma[10][10]; printf ("Enter the order of the matrix m and n "); scanf ("%dx%d",&m,&n); if (m==n){ printf ("Enter the co-efficients of the matrix
"); for (i=0;i
"); for (i=0;i
"); } for (i=0;i
"); printf ("Main & secondary diagonal
"); for (i=0;i
"); } } else printf ("The given order is not square matrix
"); }
Run 1: Enter the order of the matrix m and n 3x3 Enter the co-efficient of the matrix 1 2 3 4 5 6 7 8 9 The given matrix is 1 2 3 4 5 6 7 8 9 Matrix after changing the Main & secondary diagonal 3 2 1 4 5 6 9 8 7 Run 2: Enter the order of the matrix m and n 4x3 The given order is not square matrix
以上が指定された行列の対角要素を交換する C プログラムの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。