Advanced 2-D Array Operations in C++ Programming

a rrays two dimension 2 d cont n.w
1 / 8
Embed
Share

Dive into the world of 2-D arrays in C++ through a comprehensive tutorial covering various operations like finding sums along diagonals, manipulating diagonals, and matrix multiplication. Get detailed insights on how to work with 2-D arrays efficiently.

  • C++
  • Array Operations
  • 2-D Arrays
  • Programming
  • Tutorial

Uploaded on | 1 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. ARRAYS : TWO DIMENSION (2-D) CONT. IN C++ LANGAUGE ThirteenLecture

  2. A [ n , n ] main diagonal secondary diagonal 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 CONDITIONS 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

  3. 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

  4. 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? 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; 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

  5. 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

  6. 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] c[2][4] a[2][3] = *

  7. 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; } }

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

Related


More Related Content