ARRAYS TWO DIMENSION 2 D CONT IN C

  • Slides: 8
Download presentation
ARRAYS : TWO DIMENSION (2 -D) CONT. IN C++ LANGAUGE Setting By : A.

ARRAYS : TWO DIMENSION (2 -D) CONT. IN C++ LANGAUGE Setting By : A. L. Waleed Rasheed

main diagonal secondary diagonal A[n, n] ﺍﻟﻘﻄﺮ ﺍﻟﺮﺋﻴﺴﻲ CONDITIONS ﺍﻟﻘﻄﺮ ﺍﻟﺜﺎﻧﻮﻱ 0, 0 0,

main diagonal secondary diagonal A[n, n] ﺍﻟﻘﻄﺮ ﺍﻟﺮﺋﻴﺴﻲ CONDITIONS ﺍﻟﻘﻄﺮ ﺍﻟﺜﺎﻧﻮﻱ 0, 0 0, 1 0, 2 0, 3 0, 4 1, 0 1, 1 1, 2 1, 3 1, 4 2, 0 2, 1 2, 2 2, 3 2, 4 3, 0 3, 1 3, 2 3, 3 3, 4 4, 0 4, 1 4, 2 4, 3 4, 4 ﺍﻟﻘﻄﺮ ﺍﻟﺮﺋﻴﺴﻲ i == j main diagonal i > j Triangle under main diagonal i < j Triangle above main diagonal ﺍﻟﻘﻄﺮ ﺍﻟﺜﺎﻧﻮﻱ i+j == n-1 secondary diagonal i+j > n-1 Triangle under secondary diagonal i+j < n-1 Triangle above secondary diagonal

Q / write a program section with array 2 -D a[5, 5], to find

Q / write a program section with array 2 -D a[5, 5], to find sum No. in main diagonal? s=0; for ( i = 0; i < 5; i++) for ( j = 0; j < 5; j++) if (i==j) s+=a[i][j]; cout<<“sum = "<<s; 0, 0 0, 1 0, 2 0, 3 0, 4 1, 0 1, 1 1, 2 1, 3 1, 4 2, 0 2, 1 2, 2 2, 3 2, 4 3, 0 3, 1 3, 2 3, 3 3, 4 4, 0 4, 1 4, 2 4, 3 4, 4

Q / write a program section with array 2 -D a[5, 5], to calculate

Q / write a program section with array 2 -D a[5, 5], to calculate the sum of positive No. in Triangle under main diagonal and sum of negative No. in Triangle above secondary diagonal? s 1=s 2=0; for ( i = 0; i < 5; i++) for ( j = 0; j < 5; j++) { if (i>j && a[i][j]>=0) s 1+=a[i][j]; if ( i+j<4 && a[i][j]<0) s 2+=a[i][j]; } cout<<“Pos. No. = "<<s 1; cout<<“Neg. No. = "<<s 2; 0, 0 0, 1 0, 2 0, 3 0, 4 1, 0 1, 1 1, 2 1, 3 1, 4 2, 0 2, 1 2, 2 2, 3 2, 4 3, 0 3, 1 3, 2 3, 3 3, 4 4, 0 4, 1 4, 2 4, 3 4, 4

Q / write program section to switch the main diagonal place the secondary diagonal

Q / write program section to switch the main diagonal place the secondary diagonal in the matrix A[5, 5]? for (i=0; i<5; i++) for (j=0; j<5; j++) if (i==j) { t=a[i][j]; a[i][j]=a[i][5 -j-1]; a[i][5 -j-1]=t; } 0, 0 0, 1 0, 2 0, 3 0, 4 1, 0 1, 1 1, 2 1, 3 1, 4 2, 0 2, 1 2, 2 2, 3 2, 4 3, 0 3, 1 3, 2 3, 3 3, 4 4, 0 4, 1 4, 2 4, 3 4, 4

Q/W. P. to calculate multiply array a[2][3]*b[3][4] and print result? #include<iostream. h> void main()

Q/W. P. to calculate multiply array a[2][3]*b[3][4] and print result? #include<iostream. h> void main() { int a[2][3]={{1, 2, 3}, {4, 5, 6}}; int b[3][4]={{1, 2, 3, 4}, {4, 5, 6, 7}, {7, 8, 9, 10}}; int c[2][4]; int i, j, k; for(i=0; i<2; i++) for(j=0; j<4; j++) c[i][j]=0; b[3][4] a[2][3] * c[2][4] =

Q/W. P. to calculate multiply array a[2][3]*b[3][4] and print result? (Cont. ) for(i=0; i<2;

Q/W. P. to calculate multiply array a[2][3]*b[3][4] and print result? (Cont. ) for(i=0; i<2; i++) for(j=0; j<4; j++) { for(k=0; k<3; k++) c[i][j]+=a[i][k]*b[k][j]; } cout<<"Array c[2][4] : n"; for(i=0; i<2; i++) { for(j=0; j<4; j++) cout<<" "<<c[i][j]; cout<<endl; } }

Homework Q 1 / write program section to switch the Triangle under main diagonal

Homework Q 1 / write program section to switch the Triangle under main diagonal place Triangle above main diagonal in the matrix A[5, 5]? Q 2/W. P. to find largest No. in main diagonal and smallest No. in secondary diagonal to array a[4][4]?