+skyler_sdf Posted December 4, 2011 Report Posted December 4, 2011 Matrici-cont. 020-sorteaza crescator elementele de pe diagonala principala 021-spirala Multimi 023-diferenta a doua multimi 024-reuniunea a doua multimi 026-produsul cartezian dintre doua multimi 027-submultimi 020. #include<iostream.h> int a[30][30], i, j, m, n, aux; void main() { cout<<endl<<"dati nr de linii si de coloane: "; cin>>m>>n; for(i=0; i<=n-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-1; j++) if(a[j][j]<a[i][i]) { aux=a[i][i]; a[i][i]=a[j][j]; a[j][j]=aux; } } for(i=0; i<=n-1; i++) { for(j=0; j<=n-1; j++) cout<<a[i][j]<<" "; cout<<endl; } } 021. #include<iostream.h> void main() { int mat[10][10], n, i, j, k; cout<<"n= "; cin>>n; for(i=1; i<=n; i++) for(j=1; j<=n; j++) { cout<<"mat["<<i<<"]["<<j<<"]="; cin>>mat[i][j]; } for(k=1; k<=n/2+1; k++) { for(i=k; i<=n-k+1; i++) cout<<mat[k][i]<<endl; for(i=k+1; i<=n-k+1; i++) cout<<mat[i][n-k+1]<<endl; for(i=n-k; i>=k; i--) cout<<mat[n-k+1][i]<<endl; for(i=n-k; i>=k+1; i--) cout<<mat[i][k]<<endl; } } 023. #include<iostream.h> void main(){ int a[20], b[20], c[20], i, j, m, n, k, gasit; cout<<"n="; cin>>n; for(i=0; i<=n-1; i++) { cout<<endl<<"a["<<i<<"]="; cin>>a[i]; } cout<<endl<<"m="; cin>>m; for(i=0; i<=m-1; i++) { cout<<endl<<"b["<<i<<"]="; cin>>b[i]; } k=0; for(i=0; i<=n-1; i++) { gasit=0; for(j=0; j<=m-1 && !gasit; j++) if(a[i]==b[j]) gasit=1; if(!gasit) c[k++]=a[i]; } cout<<endl<<"A-B"<<endl; for(i=0; i<k; i++) cout<<c[i]<<" "<<endl; } 024. #include<iostream.h> void main() { int a[20], b[20], c[50], i, j, m, n, k, gasit; cout<<endl<<"nr de elemente al multimii A"; cin>>n; for(i=0; i<=n-1; i++) { cout<<endl<<"a["<<i<<"]="; cin>>a[i]; } cout<<endl<<"nr de elemente al multimii B"; cin>>m; for(i=0; i<=m-1; i++) { cout<<endl<<"b["<<i<<"]="; cin>>b[i]; } k=0; for(i=0; i<=n-1; i++) { gasit=0; for(j=0; j<=m-1 && !gasit; j++) if(a[i]==b[j]) gasit=1; if(!gasit) c[k++]=a[i]; } cout<<endl<<"A reunit cu B"; for(i=0; i<=m-1; i++) cout<<endl<<b[i]<<" "; for(i=0; i<k; i++) cout<<endl<<c[i]<<" "; } 026. #include<iostream.h> void main() { int i, m, n, j; char a[20], b[20]; cout<<"nr de elemente al multimii A: "; cin>>n; for(i=0; i<=n-1; n++) { cout<<endl<<"a["<<i<<"]="; cin>>a[i]; } cout<<endl<<"nr de elemente al multimii B: "; cin>>m; for(i=0; i<=m-1; i++) { cout<<endl<<"b["<<i<<"]="; cin>>b[i]; } for(i=0; i<n-1; i++) for(j=0; j<m-1; j++) cout<<a[i]<<" "<<b[j]<<endl; } 027. #include<iostream.h> int a[9], n, i, S; void main() { cout<<"nr de elemente al multimii A: "; cin>>n; for(i=0; i<n;) a[i++]=0; do{ a[n-1]++; for(i=n-1; i>=1; i--) if(a[i]>1) { a[i]-=2; a[i-1]+=1; } S=0; for(i=0; i<n; i++) S+=a[i]; for(i=0; i<n; i++) if(a[i]) cout<<i+1<<" "; cout<<endl; } while(S<n); cout<<"multimiea vida!!"; }
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now