0% found this document useful (0 votes)
84 views3 pages

C++ Matrice

This document presents a C++ program that calculates the transpose of a matrix and the sum of its diagonal elements. The program first inputs the rows and columns of the matrix from the user. It then inputs the elements of the matrix and displays the original matrix. It calculates the transpose by swapping the row and column indices. The program then displays the transpose and calculates the sum of the diagonal elements by adding the elements where the row and column indices are equal. It outputs the final sum.

Uploaded by

mohammedabidat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views3 pages

C++ Matrice

This document presents a C++ program that calculates the transpose of a matrix and the sum of its diagonal elements. The program first inputs the rows and columns of the matrix from the user. It then inputs the elements of the matrix and displays the original matrix. It calculates the transpose by swapping the row and column indices. The program then displays the transpose and calculates the sum of the diagonal elements by adding the elements where the row and column indices are equal. It outputs the final sum.

Uploaded by

mohammedabidat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 3

P R O G R A M M E P E R M E T TA N T D E C A L C U L E R L A M AT R I C E T R A N S P O S É E E T L A S O M M E D E D I A G O N A L E

D r BO U D J E MA A K h e lif a
P R ES EN TE D BY: A BI D AT M o h a m m e d

M A S T E R 1 R É S E A U X E T T É L É C O M M U N I C AT I O N

2022-2023
#include <iostream>
using namespace std;
int main()
{
int a[10][10], transpose[10][10], row, column, i, j,m,s;
cout << "Enter rows and columns of matrix: ";
cin >> row >> column;
cout << "\nEnter elements of matrix: " << endl;

for (int i = 0; i < row; ++i)


{
for (int j = 0; j < column; ++j)
{
cout << "Enter element a" << i + 1 << j + 1 << ": ";
cin >> a[i][j];
}
}
cout << "\nEntered Matrix: " << endl;
for (int i = 0; i < row; ++i)
{
for (int j = 0; j < column; ++j)
{
cout << " " << a[i][j];
if (j == column - 1)
cout << endl << endl;
}
}
for (int i = 0; i < row; ++i)
for (int j = 0; j < column; ++j)
{
transpose[j][i] = a[i][j];
}

cout << "\nTranspose of Matrix: " << endl;


for (int i = 0; i < column; ++i)
for (int j = 0; j < row; ++j)
{
cout << " " << transpose[i][j];
if (j == row - 1)
cout << endl << endl;
}
m=0; s=0;
for (int i = 0; i < column; ++i)
{
m=s+a[i][i];
s=m;
}
cout<<"la somme"<<s;
return 0;}
THANK YOU

You might also like