Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define nMAX 12
- typedef struct {
- int valori[nMAX][nMAX];
- int righe;
- int colonne;
- } Matr;
- Matr m1;
- void trasposta(Matr m1);
- void swap(int i, int j);
- void stampa(Matr m1);
- int main() {
- int i;
- int j;
- int a;
- int b;
- do {
- printf("Inserire la dimensione della matrice (MAX 12): ");
- scanf("%d", &b);
- } while (b > 12 && b < 1);
- m1.righe = b;
- m1.colonne = b;
- i = 0;
- while (i < m1.righe) {
- j = 0;
- while (j < m1.colonne) {
- printf("Inserire il valore: ");
- scanf("%d", &a);
- m1.valori[i][j] = a;
- j = j + 1;
- }
- i = i + 1;
- }
- stampa(m1);
- trasposta(m1);
- stampa(m1);
- return 0;
- }
- void swap(int i, int j) {
- int tmp = m1.valori[i][j];
- m1.valori[i][j] = m1.valori[j][i];
- m1.valori[j][i] = tmp;
- }
- void trasposta(Matr m1) {
- int i;
- int j;
- for (i = 0; i < m1.righe; i++)
- for (j = i; j < m1.colonne; j++)
- swap(i, j);
- }
- void stampa(Matr m1) {
- int i = 0;
- int j = 0;
- int a = 0;
- printf("La matrice contiene i seguenti valori: \n");
- while (i < m1.righe) {
- j = 0;
- while (j < m1.colonne) {
- a = m1.valori[i][j];
- printf("%d", a);
- printf(" ");
- j = j + 1;
- }
- printf("\n");
- i = i + 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement