Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- using namespace std;
- const int N=3, M=3;
- void leggi(int matrice[N][M]);
- void matricecasuale(int matrice[N][M]);
- void stampa(int matrice[N][M]);
- void diagonale(int matrice [N][M]);
- void trasposta(int matrice[N][M], int trasposta[M][N]);
- void sostituzione(int matrice[N][M]);
- int main()
- {
- int matrice[N][M], trasposta[M][N], scelta;
- cout<<"- Premere 0 per uscire -" <<endl;
- cout<<"- Premere 1 per inserire manualmente i valori della matrice -" <<endl;
- cout<<"- Premere 2 per caricare casualmente la matrice -" <<endl;
- cout<<"- Premere 3 per stampare la matrice -" <<endl;
- cout<<"- Premere 4 per stampare la diagonale principale -" <<endl;
- cout<<"- Premere 5 per trasporre la matrice -" <<endl;
- cout<<"- Premere 6 per sostiruire tutti i valori maggiori di N con 100 -" <<endl;
- cin>>scelta;
- do
- {
- switch (scelta)
- {
- case(0):
- cout<<"Grazie per avermi usato!" <<endl;
- break;
- case(1):
- leggi(matrice);
- break;
- case(2):
- matricecasuale(matrice);
- break;
- case(3):
- stampa(matrice);
- break;
- case(4):
- trasposta(matrice,trasposta);
- break;
- case(5):
- diagonale(matrice);
- break;
- case(6):
- sostituzione(matrice);
- break;
- }
- }while(scelta!=0);
- return 0;
- }
- void leggi(int matrice[N][M])
- {
- cout << "Inserisci i valori della matrice: " <<endl;
- for (int i=0; i<N; i++)
- {
- for(int j=0; j<M; j++)
- {
- cin >> matrice[i][j];
- }
- }
- }
- void matricecasuale(int matrice[N][M])
- {
- srand(time(null));
- for (int i=0; i<N; i++)
- {
- for(int j=0; j<M; j++)
- {
- matrice[i][j] = rand % 20 + 1;
- }
- }
- }
- void stampa(int matrice[N][M])
- {
- cout << "La matrice e': " <<endl;
- for (int i=0; i<N; i++)
- {
- for(int j=0; j<M; j++)
- {
- cout << matrice[i][j] <<" ";
- }
- cout <<endl;
- }
- }
- void diagonale(int matrice [N][M])
- {
- for (int i=0;i<N;i++)
- {
- cout << matrice [i][i] << " ";
- }
- cout << endl;
- }
- void trasposta(int matrice[N][M], int trasposta[M][N])
- {
- for (int i=0; i<N; i++)
- {
- for(int j=0; j<M; j++)
- {
- trasposta[j][i]=matrice[i][j];
- }
- }
- cout << "La matrice trasposta e': " <<endl;
- for(int i=0; i<M; i++)
- {
- for(int j=0; j<N; j++)
- {
- cout << trasposta[i][j] << " ";
- }
- cout <<endl;
- }
- }
- void sostituzione(int m[N][M])
- {
- int numero;
- cout<<"Inserire un numero da cercare: ";
- cin>>numero;
- for (int i=0; i<N; i++)
- {
- for(int j=0; j<M; j++)
- {
- if (matrice[i][j] > numero)
- {
- matrice[i][j] = 100;
- }
- }
- }
- cout <<"La matrice aggiornata e' : " <<endl;
- for (int i=0; i<N; i++)
- {
- for(int j=0; j<M; j++)
- {
- cout << matrice[i][j] << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement