Created by DIANA-ELENA DINU
over 4 years ago
|
||
Question | Answer |
Citire matrice | void citire(int a[][10],int &n,int &m) {int i,j; cout<<"dati nr de linii:";cin>>n; cout<<"dati nr de coloane:";cin>>m; cout<<"dati elem:"; for(i=0;i<n;i++) for(j=0;j<m;j++) {cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } } |
Afisare matrice | void afisare(int a[][10],int n,int m) {int i,j; for(i=0;i<n;i++) {for(j=0;j<m;j++) cout<<a[i][j]<<' '; cout<<endl; } } |
Adunarea matricilor
Image:
Image (binary/octet-stream)
|
int main(){ int a[100][100],b[100][100],na,ma,nb,mb,i,j; fin>>na>>ma>>nb>>mb; for(i=1;i<=na;i++)for(j=1;j<=ma;j++) fin>>a[i[j]; for(i=1;i<=nb;i++)for(j=1;j<=mb;j++) fin>>b[i][j]; //Suma nu este posibila decat daca na=nb si ma=mb if(na==nb&&ma==mb){ for(i=1;i<=na;i++){ for(j=1;j<=ma;j++) fout<<a[i][j]+b[i][j]<< ' '; fout<<endl;} |
Inmulțirea a două matrice
Image:
Image (binary/octet-stream)
|
//inmultirea a doua matrice void inmultire(matrice x, matrice y, matrice z, int n) /* in acest caz putem returna matricea prin tipul rezultat, pentru matricea este un pointer (o adresa) */ { for(int i=0;i<n;i++) for(int j=0;j<n;j++) { z[i][j]=0; for(int k=0;k<n;k++) z[i][j]+=x[i][k]*y[k][j]; } } |
Want to create your own Flashcards for free with GoConqr? Learn more.