Your SlideShare is downloading. ×
ماترێکس به‌ کوردی ئارام
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

ماترێکس به‌ کوردی ئارام

866
views

Published on

Matrix C++ Programming , Borland C++ Matrix …

Matrix C++ Programming , Borland C++ Matrix
By ARAM CSD in Kurdish Language , with Examples

Published in: Education, Technology, Business

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
866
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
9
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)Type array [size1][size2]; Row A[ i ][ j ] Column#include <iostream.h>#include <conio.h>#include <math.h>#include <cstring.h> 1. int 2. float 3. string 4. char Int const size1=?,size2=?; 1 Programming C++ ©by ARAM-CSD
  • 2. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX) x x x xInt array[size1][size2]; int i,j; i,j,n,k,l,m, main() { cin, cout,if, for(i=0;i<size1;i++) { for(j=0;j<size2;j++) { _____ _____ }} size1 i size1 size2 j size2 n=2 A2x2 cin>> for(i=0;i<n;i++) { for(j=0;j<n;j++) { cin>>a[i][j]; }} : 4 2x2 2Cin>>a[i][j];1234 2 Programming C++ ©by ARAM-CSD
  • 3. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX) a[j=0] a[i=0] a[i=0][j=0] j i <<” “ <<endl cin>>cin>>a[i][j]<<endl<<” “;cin>>a[i][j];}}cout<<endl<<” “; cout<< for(i=0;i<n;i++) { for(j=0;j<n;j++) { cout<<a[i][j]<<” “; } cout<<endl; } 1 2 3 4 i j getch(); } 3 Programming C++ ©by ARAM-CSD
  • 4. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)//write C++ program to read and print the matrix A3x3 .#include <iostream.h>#include <conio.h> Header 123456789int const n=3;int a[n][n]; Declarationint I,j; 1 2 3for(i=0;i<n;i++) 4 5 6{for(j=0;j<n;j++) 7 8 9{ INPUTcin>>a[i][j];}}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){cout <<a[i][j]<<” “; OUTPUT}cout<<endl;} getch(); } END 4 Programming C++ ©by ARAM-CSD
  • 5. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX) 1- Write C++ program to read and print out the Matrix A3x3 .then print sum of all rows.#include <iostream.h> 123456789#include <conio.h>int const n=3;int a[n][n];int sum[n]; 1 2 3int i,j; 4 5 6main(){ 7 8 9for(i=0;i<n;i++) Sum of row (1) = 6{ Sum of row (2) = 15for(j=0;j<n;j++){ Sum of row (3) = 24cin>>a[i][j];}}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){cout<<a[i][j]<<" ";}cout<<endl;}cout<<endl;for(i=0;i<n;i++){ sum[i]=0;for(j=0;j<n;j++){sum[i]=sum[i]+a[i][j];}cout<<"Sum of row ("<<(i+1)<<")="<<sum[i]<<endl;}getch();} 5 Programming C++ ©by ARAM-CSD
  • 6. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)2-Write C++ program to read and print out the Matrix A3x3 .then print sum of all columns.#include <iostream.h> 123456789#include <conio.h>int const n=3;int a[n][n];int sum[n]; 1 2 3int i,j;main() 4 5 6{ 7 8 9for(i=0;i<n;i++) Sum of column (1) = 12{for(j=0;j<n;j++) Sum of column (2) = 15{cin>>a[i][j]; Sum of column (3) = 18}}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){cout<<a[i][j]<<" ";}cout<<endl;}cout<<endl;for(j=0;j<n;j++){ sum[j]=0;for(i=0;i<n;i++){sum[j]=sum[j]+a[i][j];}cout<<"Sum of column ("<<(j+1)<<")="<<sum[j]<<endl;}getch();} 6 Programming C++ ©by ARAM-CSD
  • 7. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX) 3-write a program to read and printout Matrix Anxm, then find the sum of each row in A and Multiplication of each column in A.#include <iostream.h>#include <conio.h>int const n=3,m=2;int a[n][m];int i,j,sum[n],mult[m];main(){for(i=0;i<n;i++){for(j=0;j<m;j++){cin>>a[i][j];}}cout<<endl;cout<<"A1"<<"t"<<"A2"<<endl;cout<<"___________"<<endl;for(i=0;i<n;i++){for(j=0;j<m;j++){cout<<a[i][j]<<"t";}cout<<endl;}cout<<"____________"<<endl;for(i=0;i<n;i++){ sum[i]=0;for(j=0;j<m;j++){sum[i]=sum[i]+a[i][j];}cout<<"Sum of row ["<<(i+1)<<"]="<<sum[i]<<endl;}cout<<"_________________n"<<endl;for(j=0;j<m;j++){ mult[j]=1;for(i=0;i<n;i++){mult[j]=mult[j]*a[i][j];}cout<<"Mult of col ["<<(j+1)<<"]="<<mult[j]<<endl;}getch(); 7 Programming C++ ©by ARAM-CSD}
  • 8. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX) 4- Write program to create an array A2x2. first row are EVEN and second row are ODD.#include <iostream.h>#include <conio.h> 1 2 3 4int const n=2;int a[n][n]; __ __int i,j;main() 1 2{for(i=0;i<n;i++) 3 4{for(j=0;j<n;j++) ___________{cin>>a[i][j]; __ __}}cout<<endl;cout<<"__"<<"t"<<"__"<<endl; 2 4for(i=0;i<n;i++){ 1 3for(j=0;j<n;j++){cout<<a[i][j]<<"t";}cout<<endl;}cout<<"n__________________n";cout<<"__"<<"t"<<"__"<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){if(a[i][j]%2==0)cout<<a[i][j]<<"t";}}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){if(a[i][j]%2==1)cout<<a[i][j]<<"t";}}getch();} 8 Programming C++ ©by ARAM-CSD
  • 9. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX) 5-Write C++ program to read and print out the Matrix A3x3 when Diagonal equal to Zero.#include <iostream.h>#include <conio.h>int const n=3; 1 2 3 4 5 6 7 8 9int a[n][n];int i,j; 0 2 3main(){for(i=0;i<n;i++) 4 0 6{for(j=0;j<n;j++) 7 8 0{cin>>a[i][j];}}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){if(i==j)a[i][j]=0;}}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){cout<<a[i][j]<<" ";}cout<<"nn";}getch();} 9 Programming C++ ©by ARAM-CSD
  • 10. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)6-Write C++ program to read and print out the Matrix A3x3 .then print sum of lower triangular.#include <iostream.h>#include <conio.h> 1 2 3 4 5 6 7 8 9int const n=3;int a[n][n]; 1 2 3int i,j,l;main() 4 5 6{ 7 8 9for(i=0;i<n;i++){ Sum of Lower Triangular=11for(j=0;j<n;j++){cin>>a[i][j];}}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){cout<<a[i][j]<<" ";}cout<<"nn";}l=0;for(i=0;i<n;i++){for(j=0;j<n;j++){if(i<j)l=l+a[i][j];}}cout<<"Sum of Lower Triangular="<<l;getch();} 10 Programming C++ ©by ARAM-CSD
  • 11. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)7- Write C++ program to read and print out the Matrix A3x3 .then print sum of Upper triangular.#include <iostream.h>#include <conio.h> 1 2 3 4 5 6 7 8 9int const n=3;int a[n][n]; 1 2 3int i,j,u;main() 4 5 6{ 7 8 9for(i=0;i<n;i++){ Sum of Upper Triangular=19for(j=0;j<n;j++){cin>>a[i][j];}}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){cout<<a[i][j]<<" ";}cout<<"nn";}u=0;for(i=0;i<n;i++){for(j=0;j<n;j++){if(i>j)u=u+a[i][j];}}cout<<"Sum of Upper Triangular="<<l;getch();} 11 Programming C++ ©by ARAM-CSD
  • 12. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)8- Write C++ program read and print the matrix A3x3, and find the Identity of the matrix.#include <iostream.h>#include <conio.h> 1 2 3 4 5 6 7 8 9int const n=3;int a[n][n];int i,j,k; 1 2 3main() 4 5 6{ 7 8 9for(i=0;i<n;i++){ The identity of the Matrixfor(j=0;j<n;j++) ______________________{ 1 0 0cin>>a[i][j];}} 0 1 0cout<<endl; 0 0 1for(i=0;i<n;i++){for(j=0;j<n;j++){cout<<a[i][j]<<" ";}cout<<endl;}cout<<"nThe Identity of the Matrixn"<<"_____________________n";k=0;for(i=0;i<n;i++){for(j=0;j<n;j++){if(i==j)a[i][j]=1;elsea[i][j]=0;}}for(i=0;i<n;i++){for(j=0;j<n;j++){cout<<a[i][j]<<" ";}cout<<"n";}getch();} 12 Programming C++ ©by ARAM-CSD
  • 13. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)9- Write C++ program read and print the matrix A3x3, and find the Trace of the matrix.#include <iostream.h>#include <conio.h> 1 2 3 4 5 6 7 8 9int const n=3;int a[n][n];int i,j,k; 1 2 3main() 4 5 6{ 7 8 9for(i=0;i<n;i++){ The Trace of the Matrix=15for(j=0;j<n;j++){cin>>a[i][j];}}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){cout<<a[i][j]<<" ";}cout<<endl;}cout<<endl;k=0;for(i=0;i<n;i++){for(j=0;j<n;j++){if(i==j){k=k+a[i][j];}}}cout<<"nThe Trace of the Matrix="<<k;getch();} 13 Programming C++ ©by ARAM-CSD
  • 14. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)10- Write C++ program read and print the matrix A3x3, and make the lower triangular=0. #include <iostream.h> #include <conio.h> 1 2 3 4 5 6 7 8 9 int const n=3; int a[n][n]; 1 2 3 int i,j; main() 4 5 6 { 7 8 9 for(i=0;i<n;i++) { for(j=0;j<n;j++) 1 0 0 { 4 5 0 cin>>a[i][j]; 7 8 9 }} cout<<endl; for(i=0;i<n;i++) { for(j=0;j<n;j++) { cout<<a[i][j]<<" "; }cout<<endl;} cout<<endl; for(i=0;i<n;i++) { for(j=0;j<n;j++) {if(i<j) a[i][j]=0; cout<<a[i][j]<<” “; } cout<<endl; } getch(); } 14 Programming C++ ©by ARAM-CSD
  • 15. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)11- Write C++ program read and print the matrix A3x3, then check whether is symmetric ornot. #include <iostream.h> #include <conio.h> 1 2 3 4 5 6 7 8 9 int const n=3; int a[n][n]; int i,j,k; 1 2 3 main() 4 5 6 { 7 8 9 for(i=0;i<n;i++) { The Matrix is not symmetric for(j=0;j<n;j++) { cin>>a[i][j]; }} cout<<endl; for(i=0;i<n;i++) { for(j=0;j<n;j++) 1 2 3 2 5 6 3 6 9 { cout<<a[i][j]<<" "; }cout<<endl;} 1 2 3 cout<<endl; 2 5 6 k=0; for(i=0;i<n;i++) 3 6 9 { The Matrix is symmetric for(j=0;j<n;j++) {if(a[i][j]==a[i][j]) k=k+1; }} if(k==n*n) cout<<”The Matrix is symmetric”; else cout<<”The Matrix is not symmetric”; getch(); } 15 Programming C++ ©by ARAM-CSD
  • 16. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)12- Write C++ program read and print the matrix A3x3, and make the Upper triangular=0.#include <iostream.h>#include <conio.h> 1 2 3 4 5 6 7 8 9int const n=3;int a[n][n]; 1 2 3int i,j;main() 4 5 6{ 7 8 9for(i=0;i<n;i++){for(j=0;j<n;j++) 1 2 3{ 0 5 6cin>>a[i][j]; 0 0 9}}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){cout<<a[i][j]<<" ";}cout<<endl;}cout<<endl;for(i=0;i<n;i++){for(j=0;j<n;j++){if(i>j)a[i][j]=0;cout<<a[i][j]<<” “;}cout<<endl;}getch();} 16 Programming C++ ©by ARAM-CSD