+skyler_sdf Posted December 4, 2011 Report Posted December 4, 2011 matrici 01-matrice triunghiulara superior 02-matrice triunghiulara inferior 03-determina de cate ori apare o valoare data x ca element al matricii 04-calculeaza media aritmatica a elementelor unei matrici 05-sorteaza o linie din matrice data de la tastatura 06-afiseaza numarul elemntelor pozitive, negative, nule din matrice 07-tipareste elementele pare aflate pe linii impare si coloane divizibile cu 3; 08-verifica daca doua linii date L1 si L2 sunt identice(contin aceleasi elemente in aceeasi dispunere pe coloane) 09-afiseaza maximul dintre elementele pare ale liniei L a unei matrici cu m,n linii,coloane 010-afiseaza elementele aflate deasupra diagonalei principale, inclusiv cele de pe diagonala, sub forma unui triunghi de numere; matricea este patratica cu n*nlinii*coloane 011-calculeaza numarul elementelor pozitive de sub diagonala principala 012-memoreaza intr un vector b sumele elementelor de pe fiecare linie a matricii cu m*n linii si coloane(b va reprezenta suma elementelor de pe linia i) 013-afiseaza indicii liniei/iilor pe care se afla cele mai multe valori de 1 intr o matrice 014-copiaza intr un vector elementele pozitive aflate deasupra diagonalei principale intr o matrice 015-interschimba doua linii date L1 si L2, fara a folosi alta matrice 016-afiseaza elementele in ordine crescatoare pe diagonala principala, realizand schimbarile de linii si de coloane necesare 017-sterge min 018-construieste in memorie un tablou t cu n/n linii/coloane, cu elementele nr nat, as.in.pe diagonala principala sa existe numai elemente=1, cele de pe cele doua semidiagonale paralele cu cea princi.=2, =3etc. 01. #include<iostream.h> int a[20][30], i, j, x, n; void main() { cout<<endl<<"dati numarul de linii si de coloane: "; cin>>n; for(i=0; i<n-1; i++) for(j=0; j<=n-1; j++) { cout<<endl<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } x=1; for(i=1; i<=n-1; i++) for(j=0; j<=i-1; j++) if(a[i][j]) x=0; if(!x) cout<<endl<<"nu este triunghiulara superior:"; else cout<<endl<<"este triunghiulara superior:"; } 02. #include<iostream.h> int a[20][20]; int i, j, n, x; void main() { cout<<endl<<"dati nr de linii si de coloane:"; cin>>n; for(i=0; i<=n-1; i++) for(j=0; j<=n-1; j++) { cout<<endl<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } x=1; for(i=0; i<=n-2; i++) for(j=i+1; j<=n-1; j++) if(a[i][j]) x=0; if(!x) cout<<endl<<"nu e triunghiulara inferior:"; else cout<<"e triunghiulara inferior: "; } 03. //stabileste de cate ori apare o valoare x data ca element al unei matrice #include<iostream.h> int a[20][30],i ,j, m, n, nr=0, x; void main() { cout<<"\nDati numarul de linii si de coloane:"; cin>>m>>n; cout<<"x="; cin>>x; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<endl<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; if(a[i][j]==x) nr++; } cout<<endl<<"nr="<<nr; } 04. //determina media aritmetica a elementelor unei matrice #include<iostream.h> int a[20][30], i, j, m, n, s=0; void main() { cout<<"\nDati numarul de linii si de coloane:"; cin>>m>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<"a["<<i<<"]["<<j<<"]"; cin>>a[i][j]; s+=a[i][j]; } cout<<"Media aritmetica este egala cu:"<< (float)s/m*n; } 05. //determina media aritmetica a elementelor unei matrice #include<iostream.h> int a[20][30], i, j, m, n, s=0; void main() { cout<<"\nDati numarul de linii si de coloane:"; cin>>m>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<"a["<<i<<"]["<<j<<"]"; cin>>a[i][j]; s+=a[i][j]; } cout<<"Media aritmetica este egala cu:"<< (float)s/m*n; } 05. #include<iostream.h> int a[30][30], i, j, m, n, L, C1, C2, aux, k; void main() { cout<<"\nDati numarul de linii si de coloane: \n"; cin>>m>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } cout<<"dati linia pe care o sortez:"; cin>>L; for(C1=0; C1<=n-2; C1++) for(C2=C1+1; C2<=n-1; C2++) { if(a[L][C2]<a[L][C1]) for( k=1; k<=m-1; k++) { aux=a[k][C1]; a[k][C1]=a[k][C2]; a[k][C2]=aux; } } for(i=0; i<=m-1; i++) { for(j=0; j<=n-1; j++) cout<<a[i][j]<< " "; cout<<endl; } } 06. #include<iostream.h> int a[20][30], i, j, m, n, nn, np, nl; void main() { cout<<"m="; cin>>m; cout<<"n="; cin>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } np=nn=nl=0; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) if(a[i][j]>0) np++; if(a[i][j]<0) nn++; if(a[i][j]==0) nl++; cout<<"np="<<np; cout<<endl; cout<<"nn="<<nn; cout<<endl; cout<<"nl="<<nl; } 07. #include<iostream.h> int a[20][30], i, j, m, n; void main() { cout<<"m="; cin>>m; cout<<"n="; cin>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } for(i=1; i<=m; i+=2) for(j=0; j<=n-1; j+=3) if(a[i][j]%2==0) cout<<a[i][j]<<" "; } 08. #include<iostream.h> int a[20][30], i, j, m, n, L1, L2, ok=1; void main() { cout<<"m="; cin>>m; cout<<"n="; cin>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } for(i=0; i<=m-1; i++) if(a[L1][i]!=a[L2][i]) ok=0; if(ok) cout<<"liniile sunt identice!!!"; else cout<<endl<<"liniile nu sunt identice"; } 09. #include<iostream.h> #include<values.h> int a[20][30], i, j, m,n, L, max; void main() { cout<<"m="; cin>>m; cout<<"n="; cin>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<"a["<<i<<"]]"<<j<<"]="; cin>>a[i][j]; } cout<<"\nDati linia:"; cin>>L; max=-MAXINT+1; for(j=0; j<=n-1; j++) if(a[L][j]%2==0 && a[L][j]>max) max=a[L][j]; cout<<"max"<<max; } 010. #include<iostream.h> int a[20][30], i, j, m; void main() { cout<<"\nDati nr de linii si de coloane:"; cin>>m; for(i=0; i<=m-1; i++) for(j=0; j<=m-1; j++) { cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } for(i=0; i<=m-1; i++) { for(j=0; j<=m-1; j++) if(j>=i) cout<<a[i][j]<<" "; else cout<<" "<<" "; cout<<endl; } } 011. #include<iostream.h> int a[20][30], i, j, m, nr=0; void main() { cout<<"\nDati numarul de linii si de coloane"; cin>>m; for(i=0; i<=m-1; i++) for(j=0; j<=m-1; j++) { cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } for(i=0; i<=m-1; i++) { for(j=0; j<=m-1; j++) if(j<i) nr++; } cout<<"\nNumarul elementelor pozitive aflate sub diagonala principala este egal cu: "<<nr; } 012. #include<iostream.h> int a[20][30], i, j, m, n, b[20], k=0; void main() { cout<<"m="; cin>>m; cout<<"n="; cin>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } for(i=0; i<=m-1; i++) { for(j=0; j<=n-1; j++) b[k]+=a[i][j]; k++; } for(k=0; k<=m-1; k++) cout<<b[k]<<" "; } 013. include<iostream.h> #include<values.h> int a[20][30], b[20], i, j, m, n, k=0, max; void main() { cout<<"m="; cin>>m; cout<<"n="; cin>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<endl<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } max=-MAXINT; for(i=0; i<=m-1; i++) { for(j=0; j<=n-1; j++) b[k]+=a[i][j]; k++; } for(k=0; k<=m-1; k++) { if(b[k]>max) max=b[k]; } cout<<endl<<"Pozitiile maximului sunt: "; for(k=0; k<=m-1; k++) if(b[k]==max) cout<<k<<" "; } 014. #include<iostream.h> int a[20][30], i, j, m, n, b[20], k=0; void main() { cout<<"m="; cin>>m; cout<<"n="; cin>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<endl<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } for(i=0; i<=m-2; i++) for(j=i+1; j<=n-1; j++) if(a[i][j]>0) { b[k]=a[i][j]; k++; } m=k; for(k=0; k<=m-1; k++) cout<<b[k]<<" "; } 015. #include<iostream.h> int a[20][30], i, j, m, n, L1, L2, temp; void main() { cout<<"m="; cin>>m; cout<<"n="; cin>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<endl<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } cout<<"Dati liniile pe care le interschimb:"; cin>>L1>>L2; for(j=0; j<=n-1; j++) { temp=a[L1][j]; a[L1][j]=a[L2][j]; a[L2][j]=temp; } for(i=0; i<=m-1; i++) { for(j=0; j<=n-1; j++) cout<<endl<<a[i][j]<<" "; } } 016. #include<iostream.h> int a[20][30], i, j, m, n, aux, temp; void main() { cout<<"m="; cin>>m; cout<<"n="; cin>>n; for(i=0; i<=m-1; i++) for(j=0; j<=n-1; j++) { cout<<endl<<"a["<<i<<"]["<<j<<"]="; cin>>a[i][j]; } for(i=0; i<=m-1; i++) { for(j=i+1; j<=n; j++) if(a[j][j]<a[i][i]) { for(i=0; i<=m-1; i++) { aux=a[i][i]; a[i][i]=a[j][i]; a[j][i]=aux; } for(j=0; j<=n-1; j++) { temp=a[i][i]; a[i][i]=a[i][j]; a[i][j]=temp; } } } for(i=0; i<=m-1; i++) { for(j=0; j<=n-1; j++) cout<<a[i][j]<<" "; } } 017. #include<iostream.h> #include<values.h> int a[20], i, n, min; void main() { cout<<"n="; cin>>n; for(i=0; i<=n-1; i++) { cout<<endl<<"a["<<i<<"]="; cin>>a[i]; } min=MAXINT; do{ if(a[i]<min) min=a[i]; i++; } while(min<0 || min>n-2); for(i=min+1; i<=n-1; i++) a[i-1]=a[i]; for(i=0; i<=n-2; i++) cout<<a[i]<<" "; } 018. #include<iostream.h> int a[20][20], i, j, n, k; void main() { cout<<endl<<"n="; cin>>n; for(i=0; i<=n-1; i++) { a[i][i]=1; for(k=i+1; k<=n-1; k++) a[i][k]=a[i][k-1]+1; for(k=i-1; k>=0; k--) a[i][k]=a[i][k+1]+1; } for(i=0; i<=n-1; i++) { for(j=0; j<=n-1; j++) cout<<a[i][j]<<" "; cout<<endl; } } 2
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now