3 matrix in c++ programming aramse

249 views
174 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
249
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

3 matrix in c++ programming aramse

  1. 1. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)1 Programming C++ ©by ARAM-CSD.‫کۆلۆم‬ ‫ڵێن‬‫ده‬ ‫پێی‬ ‫ستوونی‬ ‫دووری‬ ‫ڕۆو‬ ‫ڵێن‬‫ده‬ ‫پێی‬ ‫ئاسۆیی‬ ‫دووری‬ ‫که‬ ‫پێکهاتووه‬ ‫دووری‬ ‫دوو‬ ‫له‬ :‫ماترێکس‬‫بنه‬‫له‬ ‫دورری‬ ‫دوو‬ ‫بوونی‬ ‫دروست‬ ‫گشتی‬ ‫مای‬‫ڕیزکراوه‬‫به‬ ‫کاندا‬‫شێوه‬ ‫م‬‫یه‬‫یه‬:‫جۆر‬ ‫ناو‬ ‫قه‬‫باره‬2‫قه‬‫باره‬1Type array [size1][size2];A[ i ][ j ]‫سه‬‫ره‬‫پێویسته‬ ‫تا‬‫وه‬‫هه‬ ‫کو‬‫به‬ ‫موو‬‫رنامه‬‫هێده‬ ( ‫پێشوو‬ ‫کانی‬‫که‬ ‫بنووسین‬ ‫بۆ‬ ‫ر)ی‬‫به‬‫سه‬ ‫شێکی‬‫ره‬‫به‬ ‫کی‬‫رنامه‬‫که‬‫یه‬.‫وه‬‫ئه‬‫گه‬‫به‬ ‫پێویستمان‬ ‫ر‬‫هه‬‫ده‬ ‫بوو‬ ‫تر‬ ‫کردارێکی‬ ‫جۆر‬ ‫ر‬‫له‬ ‫بێ‬‫هێده‬‫بکه‬ ‫زیادی‬ ‫ردا‬‫وه‬ ‫ین‬‫ک‬(‫که‬ ‫بیرکاری‬ ‫حساباتی‬‫توانی‬)‫تێده‬‫که‬‫یان‬ ،‫وێت‬‫حه‬ ‫و‬ ‫تێکست‬ (‫نووسین‬‫له‬ )‫رف‬‫به‬‫رنامه‬‫که‬.‫دا‬1.#include <iostream.h>2.#include <conio.h>3.#include <math.h>4.#include <cstring.h>‫یه‬ ‫خاڵی‬‫که‬‫دووه‬ ‫و‬ ‫م‬‫سه‬ ‫م‬‫ره‬‫هێده‬ ‫بۆ‬ ‫کین‬‫ره‬‫که‬‫که‬‫ده‬‫له‬ ‫بێت‬‫هه‬‫به‬ ‫موو‬‫رنامه‬‫یه‬‫به‬ ‫بنووسرێت‬ ‫کدا‬:‫اڵم‬‫خاڵێ‬3‫به‬‫که‬ ‫بیرکاری‬ ‫(حساباتی‬ ‫بۆ‬ ‫کاردێت‬‫توان‬،‫ڕه‬‫گ‬،‫ته‬.)... ‫ژێ‬‫خاڵی‬4‫به‬‫حه‬ ‫و‬ ‫تێکست‬ ( ‫بۆ‬ ‫کاردێت‬‫له‬ )‫رف‬‫به‬‫رنامه‬‫که‬.‫دا‬‫ده‬ ‫پاشان‬‫چینه‬‫به‬‫شی‬‫(دیکله‬‫ره‬)‫یشن‬‫که‬‫ئه‬‫به‬ ‫م‬‫شه‬‫به‬‫که‬ ‫دێت‬ ‫لێدوان‬ ‫مانای‬‫ئه‬ ‫تیایدا‬‫وشتانه‬‫که‬ ‫ی‬‫پێویستمانه‬‫ده‬‫یان‬‫به‬ ‫ناسێنین‬‫به‬‫رنامه‬‫که‬‫ئه‬‫جۆره‬ ‫چوار‬ ‫میش‬:1. int ‫ئینتیجه‬‫به‬ ‫ر‬‫ژماره‬ ‫بۆ‬ ‫کاردێت‬‫ته‬ ‫ی‬‫واوه‬‫کان‬2. float ‫به‬ ‫فلۆت‬‫ڕێژه‬ ‫ژماره‬ ‫بۆ‬ ‫دێت‬ ‫کار‬‫یه‬‫کان‬3. string ‫به‬ ‫سترینگ‬‫وشه‬ ‫نوسینی‬ ‫بۆ‬ ‫کاردێت‬‫ناو‬ ‫یان‬4. char ‫کاره‬‫کته‬‫به‬ ‫ر‬‫ته‬ ‫نوسینی‬ ‫بۆ‬ ‫کاردێت‬‫یه‬ ‫نها‬‫حه‬ ‫ک‬‫رف‬‫له‬‫به‬ ‫پێویستمان‬ ‫دا‬ ‫ماترێکس‬‫نه‬‫گۆڕێکه‬‫که‬‫ده‬‫له‬ ‫بێت‬‫سه‬‫ره‬‫بکه‬ ‫داغڵی‬ ‫تادا‬‫له‬ ‫ین‬‫(هێده‬ ‫دوای‬‫ر)ه‬‫وه‬‫به‬‫م‬‫شێوه‬:‫یه‬Int const size1=?,size2=?;‫ئاسۆی‬ Row‫ستوونی‬ Column
  2. 2. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)2 Programming C++ ©by ARAM-CSD‫ئه‬‫گه‬‫ژماره‬ ‫ر‬‫یه‬ ‫ستوونی‬ ‫و‬ ‫ئاسۆی‬ ‫ی‬‫وه‬ ‫بوو‬ ‫کسان‬‫ک‬3x3،2x2‫ئه‬‫ته‬ ‫وا‬‫نها‬1‫قه‬‫باره‬‫پێویسته‬ ‫مان‬‫به‬‫ئه‬ ‫اڵم‬‫گه‬‫ر‬‫ئه‬ ‫بوو‬ ‫جیاواز‬‫ده‬ ‫وا‬‫دوو‬ ‫بێت‬2x3،3x4‫ئه‬‫ده‬ ‫وا‬‫قه‬ ‫دوو‬ ‫بێت‬‫باره‬.‫بنووسین‬ ‫جیاواز‬ ‫ی‬‫لێره‬‫ده‬ ‫دا‬‫چینه‬‫سه‬‫به‬ ‫ر‬‫ئه‬ ‫تر‬ ‫شێکی‬‫ماترێکسه‬ ‫ناساندنی‬ ‫ویش‬‫که‬‫یه‬‫به‬‫شێوه‬ ‫م‬‫یه‬Int array[size1][size2];‫هه‬ ‫پاشان‬‫به‬ ‫شتێکمان‬ ‫ر‬‫وه‬ ‫بیناسێنین‬ ‫پێوستا‬ ‫کارهێنا‬( ‫ک‬i,j,n,k,l,m,)int i,j;‫پاشان‬main(){‫ده‬‫ده‬ ‫نووسین‬‫ده‬ ‫ست‬‫که‬‫به‬ ‫ین‬‫به‬‫رنامه‬‫داڕشتنه‬‫که‬.‫ته‬‫ئه‬ ‫نها‬‫نه‬ ‫وشتا‬‫که‬ ‫بێت‬‫له‬‫سه‬‫ره‬‫وه‬‫ناساندوومانه‬‫وه‬‫قه‬ ‫ک‬‫باره‬‫وه‬ ‫ناو‬ ‫و‬‫دووباره‬ ‫نابێت‬.‫ناسێنین‬ ‫بیان‬‫له‬‫هه‬ ‫بۆ‬ ‫دا‬ ‫ماترێکس‬‫به‬ ‫پێویستمان‬ ‫کردارێک‬ ‫موو‬‫ده‬ ‫لووپ‬ ‫دوو‬‫که‬ ‫بێت‬‫به‬‫د‬ )‫(فۆڕ‬‫ه‬.‫کرێت‬‫وه‬( ‫ک‬cin, cout,if,‫وه‬ )‫هه‬‫که‬ ‫تر‬ ‫کردارێکی‬ ‫ر‬.‫بوو‬ ‫پێویست‬for(i=0;i<size1;i++){for(j=0;j<size2;j++){__________}}‫لێره‬‫یه‬ ‫لووپی‬‫که‬‫که‬ ‫م‬‫به‬(i( ‫و‬ )size1‫به‬ )‫ستراوه‬‫به‬‫ڕیزه‬ ‫بۆ‬ ‫کاردێت‬‫ئاسۆیه‬‫که‬ ‫کان‬‫له‬‫ده‬ ‫سفر‬‫پێده‬ ‫ست‬‫تا‬ ‫کات‬‫دانه‬‫یه‬‫که‬ ‫ک‬‫متر‬‫له‬(size1.)‫وه‬‫دووه‬ ‫لووپی‬‫که‬ ‫م‬‫به‬(j( ‫و‬ )size2‫به‬ )‫ستراوه‬‫به‬‫ڕیزه‬ ‫بۆ‬ ‫کاردێت‬‫ستوونیه‬‫که‬ ‫کان‬‫له‬‫ده‬ ‫سفر‬‫پێده‬ ‫ست‬‫تا‬ ‫کات‬‫دانه‬‫یه‬‫که‬ ‫ک‬‫له‬ ‫متر‬(size2.)( ‫کردن‬ ‫داغڵ‬ /‫أ‬cin>>:)‫ماترێکسی‬ :‫نموونه‬ ‫بۆ‬A2x2‫که‬‫قه‬‫باره‬‫کامان‬n=2‫قه‬‫باره‬‫یه‬ ‫یان‬‫کسانه‬for(i=0;i<n;i++){for(j=0;j<n;j++){cin>>a[i][j];}}‫لێره‬‫له‬ ‫دا‬‫به‬‫ئه‬ ‫ر‬‫وه‬‫قه‬ ‫ی‬‫باره‬‫که‬= ‫مان‬2‫واته‬2x2‫ده‬‫بێت‬4‫ژماره‬‫بکه‬ ‫داغڵ‬‫به‬ ‫ین‬‫شێوه‬ ‫م‬‫یه‬‫خواره‬ ‫ی‬‫وه‬:Cin>>a[i][j];1 2 3 4
  3. 3. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)3 Programming C++ ©by ARAM-CSD‫لێره‬‫که‬ ‫کاتێک‬ ‫دا‬‫ژماره‬‫ده‬ ‫داخڵ‬‫که‬‫ده‬ ‫ین‬‫که‬ ‫بزانین‬ ‫بێ‬‫یه‬‫که‬‫ژماره‬ ‫م‬‫ده‬‫چێته‬a[i=0]‫وه‬‫دووه‬‫ژماره‬ ‫م‬‫ده‬‫چێته‬a[j=0]‫واته‬a[i=0][j=0]‫یه‬‫که‬‫ژماره‬ ‫م‬‫دووه‬ ‫و‬‫ژماره‬ ‫م‬‫ده‬‫که‬ ‫گرن‬‫به‬‫شێوه‬‫ناوه‬ ‫دامان‬ ‫لوپ‬ ‫دوو‬ ‫ی‬‫واته‬‫هه‬‫موو‬‫کرداره‬‫په‬ ‫کانمان‬‫یوه‬‫به‬ ‫ندی‬i‫و‬j‫هه‬‫یه‬‫که‬‫ماتریک‬ ‫بۆ‬ ‫گرنگن‬ ‫زۆر‬‫س‬‫له‬‫به‬.‫کارهێنانیاندا‬‫به‬ // ‫تێبینی‬‫شێوه‬ ‫هیچ‬‫یه‬‫ک‬cin>>‫واته‬‫ئینپوت‬<<endl‫و‬<<” “‫وه‬‫راسته‬ ‫رناگرێت‬‫به‬ ‫وخۆ‬‫شێوه‬ ‫م‬‫یه‬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 23 4‫که‬‫ڕه‬‫نگه‬‫سووره‬‫ده‬‫به‬ ‫بێت‬‫یه‬ ‫ڕیزی‬‫که‬‫واته‬ ‫م‬‫مانای‬i‫ده‬‫گه‬‫یه‬‫وه‬ ‫نێت‬‫ڕه‬‫نگه‬‫شینه‬‫که‬‫ده‬‫به‬ ‫بێت‬‫دووه‬ ‫ڕیزی‬‫واته‬ ‫م‬j‫ده‬‫گه‬‫یه‬.‫نێت‬‫وه‬‫له‬‫هه‬ ‫دوا‬‫ئه‬ ‫مووی‬‫مانه‬‫ئه‬ ‫بۆ‬‫وه‬‫شاشه‬ ‫ی‬‫ڕه‬‫شه‬‫که‬‫ده‬ ‫بۆ‬ ‫مان‬‫ربکه‬‫النه‬ ‫و‬ ‫وێت‬‫دایده‬ ‫خۆمان‬ ‫تا‬ ‫چێت‬‫خه‬‫ین‬‫ده‬:‫نووسین‬getch();}
  4. 4. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)4 Programming C++ ©by ARAM-CSD‫ئێسته‬‫ئه‬‫گه‬‫هه‬ ‫ر‬‫ئه‬ ‫موو‬‫کردارانه‬ ‫و‬‫سه‬ ‫ی‬‫ره‬‫وه‬‫بکه‬‫به‬ ‫ین‬‫قه‬ ‫ماترێکسێکی‬‫باره‬3‫به‬‫شێوه‬ ‫م‬‫یه‬‫ده‬‫رده‬:‫چێت‬//write C++ program to read and print the matrix A3x3 .1 2 3 4 5 6 7 8 91 2 34 5 67 8 9for(i=0;i<n;i++){for(j=0;j<n;j++){ INPUTcin>>a[i][j];}}cout<<endl;int const n=3;int a[n][n]; Declarationint I,j;#include <iostream.h>#include <conio.h>for(i=0;i<n;i++){for(j=0;j<n;j++){cout <<a[i][j]<<” “; OUTPUT}cout<<endl;}getch();}HeaderEND
  5. 5. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)5 Programming C++ ©by ARAM-CSD‫لێره‬‫کۆمه‬ ‫دا‬‫نموونه‬ ‫ڵێک‬‫داناوه‬ ‫شیکارکراوم‬ ‫ی‬‫ئه‬ ‫بۆ‬‫وه‬‫بگه‬ ‫تێ‬ ‫لێێ‬ ‫زیاتر‬ ‫ی‬‫ن‬1- Write C++ program to read and print out the Matrix A3x3 .then print sum of all rows.#include <iostream.h>#include <conio.h>int const n=3;int a[n][n];int sum[n];int i,j;main(){for(i=0;i<n;i++){for(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;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();}1 2 3 4 5 6 7 8 91 2 34 5 67 8 9Sum of row (1) = 6Sum of row (2) = 15Sum of row (3) = 24
  6. 6. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)6 Programming C++ ©by ARAM-CSD2-Write C++ program to read and print out the Matrix A3x3 .then print sum of all columns.#include <iostream.h>#include <conio.h>int const n=3;int a[n][n];int sum[n];int i,j;main(){for(i=0;i<n;i++){for(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;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();}1 2 3 4 5 6 7 8 91 2 34 5 67 8 9Sum of column (1) = 12Sum of column (2) = 15Sum of column (3) = 18
  7. 7. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)7 Programming C++ ©by ARAM-CSD#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();}3-write a program to read and printout Matrix Anxm, then find the sum of each rowin A and Multiplication of each column in A.
  8. 8. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)8 Programming C++ ©by ARAM-CSD4- Write program to create an array A2x2. first row are EVEN and second row are ODD.#include <iostream.h>#include <conio.h>int const n=2;int a[n][n];int i,j;main(){for(i=0;i<n;i++){for(j=0;j<n;j++){cin>>a[i][j];}}cout<<endl;cout<<"__"<<"t"<<"__"<<endl;for(i=0;i<n;i++){for(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();}1 2 3 4__ __1 23 4_____________ __2 41 3
  9. 9. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)9 Programming C++ ©by ARAM-CSD5-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;int a[n][n];int i,j;main(){for(i=0;i<n;i++){for(j=0;j<n;j++){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();}1 2 3 4 5 6 7 8 90 2 34 0 67 8 0
  10. 10. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)10 Programming C++ ©by ARAM-CSD6-Write C++ program to read and print out the Matrix A3x3 .then print sum of lower triangular.#include <iostream.h>#include <conio.h>int const n=3;int a[n][n];int i,j,l;main(){for(i=0;i<n;i++){for(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();}1 2 3 4 5 6 7 8 91 2 34 5 67 8 9Sum of Lower Triangular=11
  11. 11. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)11 Programming C++ ©by ARAM-CSD7- Write C++ program to read and print out the Matrix A3x3 .then print sum of Upper triangular.#include <iostream.h>#include <conio.h>int const n=3;int a[n][n];int i,j,u;main(){for(i=0;i<n;i++){for(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();}1 2 3 4 5 6 7 8 91 2 34 5 67 8 9Sum of Upper Triangular=19
  12. 12. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)12 Programming C++ ©by ARAM-CSD8- Write C++ program read and print the matrix A3x3, and find the Identity of the matrix.#include <iostream.h>#include <conio.h>int const n=3;int a[n][n];int i,j,k;main(){for(i=0;i<n;i++){for(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<<"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();}1 2 3 4 5 6 7 8 91 2 34 5 67 8 9The identity of the Matrix______________________1 0 00 1 00 0 1
  13. 13. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)13 Programming C++ ©by ARAM-CSD9- Write C++ program read and print the matrix A3x3, and find the Trace of the matrix.#include <iostream.h>#include <conio.h>int const n=3;int a[n][n];int i,j,k;main(){for(i=0;i<n;i++){for(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();}1 2 3 4 5 6 7 8 91 2 34 5 67 8 9The Trace of the Matrix=15
  14. 14. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)14 Programming C++ ©by ARAM-CSD10- Write C++ program read and print the matrix A3x3, and make the lower triangular=0.#include <iostream.h>#include <conio.h>int const n=3;int a[n][n];int i,j;main(){for(i=0;i<n;i++){for(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;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();}1 2 3 4 5 6 7 8 91 2 34 5 67 8 91 0 04 5 07 8 9
  15. 15. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)15 Programming C++ ©by ARAM-CSD11- Write C++ program read and print the matrix A3x3, then check whether is symmetric ornot.#include <iostream.h>#include <conio.h>int const n=3;int a[n][n];int i,j,k;main(){for(i=0;i<n;i++){for(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(a[i][j]==a[i][j])k=k+1;}}if(k==n*n)cout<<”The Matrix is symmetric”;elsecout<<”The Matrix is not symmetric”;getch();}1 2 3 4 5 6 7 8 91 2 34 5 67 8 9The Matrix is not symmetric1 2 3 2 5 6 3 6 91 2 32 5 63 6 9The Matrix is symmetric
  16. 16. May 13, 2012 TWO-DIMENSIONAL ARRAYS (MATRIX)16 Programming C++ ©by ARAM-CSD12- Write C++ program read and print the matrix A3x3, and make the Upper triangular=0.#include <iostream.h>#include <conio.h>int const n=3;int a[n][n];int i,j;main(){for(i=0;i<n;i++){for(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;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();}1 2 3 4 5 6 7 8 91 2 34 5 67 8 91 2 30 5 60 0 9

×