0% found this document useful (0 votes)
355 views1 page

Matrice - Patratica-Transpusa

This document contains code to read in a square matrix of size n x n from the user, calculate the transpose of the matrix, and print out the original and transposed matrices. It defines functions to read in the matrix, print the matrix with a message, and calculate the transpose by swapping elements a[i][j] and a[j][i] for i > j. The main function gets the size n, calls the functions to read the matrix, print the original, calculate and print the transpose.

Uploaded by

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

Matrice - Patratica-Transpusa

This document contains code to read in a square matrix of size n x n from the user, calculate the transpose of the matrix, and print out the original and transposed matrices. It defines functions to read in the matrix, print the matrix with a message, and calculate the transpose by swapping elements a[i][j] and a[j][i] for i > j. The main function gets the size n, calls the functions to read the matrix, print the original, calculate and print the transpose.

Uploaded by

hack.h
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//se citeste o matrice patratica A de dimensiunea n x n.

Sa se calculeze transpu
sa.
#include <stdio.h>
void
{

read_matrix(int n, double a[20][20])


int i, j;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
{
printf("a[%d][%d] = ", i, j);
scanf("%lf", &a[i][j]);
}

}
void

print_matrix(int n, double a[20][20], char msg[100])


int i, j;
printf("%s", msg);
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
printf("%5.2f", a[i][j]);
printf("\n");
}

}
void
{

transpose(int n, double a[20][20])


int i, j;
double t;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
if (i > j)
{
t = a[i][j];
a[i][j] = a[j][i];
a[j][i] = t;
}

}
int main(void)
{
int n;
double a[20][20];
printf("Introdu dimensiunea matricei (n): "); scanf("%d", &n);
read_matrix(n, a);
print_matrix(n, a, "Matricea introdusa este: \n");
transpose(n, a);
print_matrix(n, a, "Transpusa matricei este: \n");
}

You might also like