1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include <stdio.h>
#include <stdlib.h>
#define line 1000
#define sep ".,' '"
#define max 100
// programma di trasposta
void trasposta(int matrice[][max],int righe,int colonne){
int i,j;
for (i=0;i<righe;i++){
for(j=0;j<colonne;j++){
matrice[i][j]=matrice[j][i];
}
}
}
//function riempi matrice
void genera(int matrice[][max],int righe,int colonne){
int i,j;
for (i=0;i<righe;i++){
for (j=0;j<colonne;j++){
matrice[i][j]=rand();
}
}
}
//function stampa
void stampa(int matrice[][max],int righe,int colonne){
int i,j;
for (i=0;i<righe;i++){
for(j=0;j<colonne;j++){
printf("Matrice e : \n");
printf("\t%d\t",matrice[i][j]);
}
printf("\n");
}
}
// function get string turn integer
int riempi_in(int matrice[][10],int righe,int colonne){
char linea[line];
char *word;
// int counta=0;
int i,j;
for(i=0;i<righe;i++){
printf("\nIntroduce prossima righe: ");
gets(linea);
for (j=0;j<colonne;j++){
if (strlen(linea)>0){ // ligne 53
word=strtok(linea,sep); // ligne 54
matrice[i][j]=atoi(word);
while(word){
word=strtok(NULL,sep);//ligne 57
}
}
}
}
return 0;
}
//function principale
int main(void){
int ri,col;
char stringa[100];
int tabella1[max][max];
int tabella2[max][max];
int tabella3[max][max];
printf("Domanda a \n ");
genera(tabella1,10,10);
trasposta(tabella1,10,10);
printf("Domanda b \n");
printf("Righe(max 100) : ");
scanf("%d",&ri);
prinft("colonne (max 100) : ");
scanf("%d",&col);
riempi_in(tabella2,ri,col);// ligne 81
trasposta(tabella2,ri,col);
stampa(tabella2,ri,col);
printf("\n Domanda c");
genera(tabella3,10,10);
trasposta(tabella3,10,10);
stampa(tabella3,10,10);
printf("\n END");
return 0;
} |
Partager