Arrays : two dimension (2-D) cont. Setting By : A. L. Waleed Rasheed Thirteen Lecture IN C LANGAUGE CONDITIONS main diagonal secondary diagonal i j main diagonal i j Triangle under main diagonal i j Triangle above main
Related Topics
Share
Embed code
Download this presentation From Below
"Arrays : two dimension (2-D) cont. Setting By : A." is the property of its rightful owner. Permission is granted to
download and print the materials on this website for personal, non-commercial use only, and to display it
on your personal computer provided you do not modify the materials and that you retain all copyright
notices contained in the materials. By downloading content from our website, you accept the terms of this
agreement.
Presentation Transcript
01
Arrays : two dimension (2-D)cont. Setting By : A. L. Waleed Rasheed Thirteen Lecture IN C++ LANGAUGE<br>
02
CONDITIONS main diagonal secondary diagonal 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 القطر الرئيسي القطر الثانوي A [ n , n ]<br>
03
s=0;
for ( i = 0; i < 5; i++)
for ( j = 0; j < 5; j++)
if (i==j) s+=a[i][j];
cout<<“sum = "<<s; Q / write a program section with array 2-D a[5,5], to find sum No. in main diagonal?<br>
04
s1=s2=0;
for ( i = 0; i < 5; i++)
for ( j = 0; j < 5; j++)
{
if (i>j && a[i][j]>=0) s1+=a[i][j];
if ( i+j<4 && a[i][j]<0) s2+=a[i][j];
}
cout<<“Pos.No.= "<<s1;
cout<<“Neg.No.= "<<s2; 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?<br>
05
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; } Q / write program section to switch the main diagonal place the secondary diagonal in the matrix A[5,5]?<br>
06
#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; Q/W.P. to calculate multiply array a[2][3]*b[3][4] and print result? a[2][3] b[3][4] c[2][4] * =<br>