Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
55 views

Data Structure and Algorithm Lab Programs

This document contains programs for various data structures and algorithms questions. It includes programs to perform operations on arrays like insertion, deletion, sorting, counting frequency. It also includes programs on linked lists to create, traverse, double values, find sum of previous element, find min and max. Programs for insertion in linked list and swapping nodes in linked lists are also provided. The programs are written in C++ with comments explaining each section.

Uploaded by

PKSachan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Data Structure and Algorithm Lab Programs

This document contains programs for various data structures and algorithms questions. It includes programs to perform operations on arrays like insertion, deletion, sorting, counting frequency. It also includes programs on linked lists to create, traverse, double values, find sum of previous element, find min and max. Programs for insertion in linked list and swapping nodes in linked lists are also provided. The programs are written in C++ with comments explaining each section.

Uploaded by

PKSachan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 51

DATA STRUCTURE AND ALGORITHM

LAB PROGRAMS

NAME: Abhinendra gaurav


ROLL. NO.: 17103002
GROUP: G1
YEAR: Second year (B.tech)
Q1.Write a program for insertion in array.

#include<iostream>
using namespace std;
int main()
{
int arr[50],i,j,n,k,loc;
cout<<"Enter no. of elements in array";
cin>>n;
cout<<"\nEnter array:\n";
for(i=0;i<n;i++)
cin>>arr[i];
cout<<"\nEnter the position and element to insert:\n";
cin>>loc>>k;
for(i=n-1;i>=loc-1;i--)
arr[i+1]=arr[i];
arr[loc]=k;n=n+1;
cout<<"The modified array is:\n";
for(i=0;i<n;i++)
cout<<arr[i]<<endl;

}
Q2.Write a program for deletion in array.

#include<iostream>
using namespace std;
int main()
{
int arr[50],i,n,loc;
cout<<"Enter no. of elements in array";
cin>>n;
cout<<"\nEnter array:\n";
for(i=0;i<n;i++)
cin>>arr[i];
cout<<"\nEnter the position of element to delete:\n";
cin>>loc;
for(i=loc-1;i<n;i++)
arr[i]=arr[i+1];
n=n-1;
cout<<"The modified array is:\n";
for(i=0;i<n;i++)
cout<<arr[i]<<endl;

}
Q3.Write a program to sort an array.

#include<iostream>
using namespace std;
int main()
{
int arr[50],i,n,j,t;
cout<<"Enter no. of elements in array";
cin>>n;
cout<<"\nEnter array:\n";
for(i=0;i<n;i++)
cin>>arr[i];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(arr[j]>arr[i])
{
t=arr[i];
arr[i]=arr[j];
arr[j]=t;

}
}
}
cout<<"The modified array is:\n";
for(i=0;i<n;i++)
cout<<arr[i]<<endl;

}
Q4.Write a program to count frequency of elements.

#include<iostream>
using namespace std;
int main()
{
int arr[50],i,n,j,count;

cout<<"Enter no. of elements in array";


cin>>n;
cout<<"\nEnter array:\n";
for(i=0;i<n;i++)
cin>>arr[i];
for(i=0;i<n;i++)
{
count=0;
for(j=0;j<n;j++)
{
if(arr[j]==arr[i])
{
count++;

}
}
cout<<"Frequency of element"<<arr[i]<<"is:
"<<count<<endl;
}

}
Q5.Write a program to reverse array without using extra
storage.

#include<iostream>
using namespace std;
int main()
{
int arr[50],i,n,mid,j;
cout<<"Enter no. of elements in array";
cin>>n;
cout<<"\nEnter array:\n";
for(i=0;i<n;i++)
cin>>arr[i];n=n-1;
if(n%2==0)
mid=n/2;
else
mid=n/2+1;
for(i=0;i<mid;i++)
{
arr[i]=arr[i]+arr[n-i];
arr[n-i]=arr[i]-arr[n-i];
arr[i]=arr[i]-arr[n-i];
}

cout<<"The modified array is:\n";


for(i=0;i<=n;i++)
cout<<arr[i]<<endl;

}
Q6.Write a program to find multiplication of matrices.

#include<iostream>
using namespace std;
int main()
{
int a[3][3],b[3][3],i,j,k,c[3][3];
cout<<"Enter first matrix:\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>a[i][j];
cout<<"\nEnter second matrix:\n";
for(i=0;i<3;i++)
for(j=0;j<3;j++)
cin>>b[i][j];
//Multiplication
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{ c[i][j]=0;
for(k=0;k<3;k++)
c[i][j]+=a[i][k]*b[k][j];
}

cout<<"\nMultiplication of two matrices:\n";


for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
cout<<c[i][j]<<" ";
}
cout<<endl;
}
}
Q7.Write a program to implement linear and binary
search.

#include<iostream>
using namespace std;
int main()
{
int a[10],i,j,beg,en,mid,n,f,c;
beg=0;en=9;j=0;c=0;f=0;
cout<<"Enter array";
for(i=0;i<10;i++)
cin>>a[i];

cout<<"Enter no. u want to search";


cin>>n;
//Linear search
for(i=0;i<10;i++)
{ c++;
if(a[i]==n)
{
f=1;
break;
}
}
if(f)
cout<<"Number found with iterations: "<<c;
else
cout<<"\nNumber not found with iterations: "<<c;
//Binary search
mid=(beg+en)/2;
while(a[mid]!=n && beg<=en)
{
if(a[mid]<n)
beg=mid+1;
else
en=mid-1;
mid=(beg+en)/2;j++;
}

if(a[mid]==n)
cout<<"\nNo. found after "<<j<<" iteration";
else
cout<<"\nNo. not found after "<<j<<" iteration";
}
LINKED LIST
Q1.Write a program to create and traverse a singly linked
list.
#include<iostream>
using namespace std;
struct node
{
int info;
node *ptr;
};
node *head,*start,*temp;
void create(int n)
{
head=new node;
head->info=n;
if(start==NULL)
{
start=temp=head;
}
else
{
temp->ptr=head;
temp=head;
}
}
void display()
{
temp=start;
while(temp!=NULL)
{
cout<<temp->info<<endl;
temp=temp->ptr;
}
}

int main()
{
int n,ch,m;
ch=1;
while(ch)
{
cout<<"Enter value to store"<<endl;
cin>>n;
create(n);
cout<<"Want to create more :0 or 1\n";
cin>>ch;
}
cout<<"\nValues in linked list are\n";
display();
}

Q2.Write a program to double the original value of


linked list.
#include<iostream>
using namespace std;
struct node
{
int info;
node *ptr;
};
node *head,*start,*temp;
void create(int n)
{
head=new node;
head->info=2*n;
if(start==NULL)
{
start=temp=head;
}
else
{
temp->ptr=head;
temp=head;
}
}
void display()
{
temp=start;
while(temp!=NULL)
{
cout<<temp->info<<endl;
temp=temp->ptr;
}
}
int main()
{
int n,ch,m;
ch=1;
while(ch)
{
cout<<"Enter value to store"<<endl;
cin>>n;
create(n);
cout<<"Want to create more :0 or 1\n";
cin>>ch;
}
cout<<"\nValues in linked list are\n";
display();
}

Q3.Write a program to implement sum of previous


element in a linked list.
#include<iostream>
using namespace std;
struct node
{
int info;
node *ptr;
};
node *head,*start,*temp;
void create(int n,int t)
{
head=new node;
head->info=t+n;
if(start==NULL)
{
start=temp=head;
}
else
{
temp->ptr=head;
temp=head;
}
}
void display()
{
temp=start;
while(temp!=NULL)
{
cout<<temp->info<<endl;
temp=temp->ptr;
}
}

int main()
{
int n,ch,m,t;
ch=1;
t=0;
while(ch)
{
cout<<"Enter value to store"<<endl;
cin>>n;
create(n,t);
t=n;
cout<<"Want to create more :0 or 1\n";
cin>>ch;
}
cout<<"\nValues in linked list are\n";
display();
}

Q4.Write a program to find min and max element in


linked list.
#include<iostream>
using namespace std;
struct node
{
int info;
node *ptr;
};
node *head,*start,*temp;
void create(int n)
{
head=new node;
head->info=n;
if(start==NULL)
{
start=temp=head;
}
else
{
temp->ptr=head;
temp=head;
}
}
void display()
{
temp=start;
while(temp!=NULL)
{
cout<<temp->info<<endl;
temp=temp->ptr;
}
}
int minimum()
{ int small=start->info;
temp=start;
while(temp!=NULL)
{
if(temp->info<small)
small=temp->info;
temp=temp->ptr;
}
return small;
}
int maximum()
{ int large=start->info;
temp=start;
while(temp!=NULL)
{
if(temp->info>large)
large=temp->info;
temp=temp->ptr;
}
return large;
}
int main()
{
int n,ch,m;
ch=1;
while(ch)
{
cout<<"Enter value to store"<<endl;
cin>>n;
create(n);
cout<<"Want to create more :0 or 1\n";
cin>>ch;
}
cout<<"\nValues in linked list are\n";
display();
cout<<"\nMinimum value of linked
list:"<<minimum();
cout<<"\nMaximum value of linked
list :"<<maximum();
}

Q5.Write a program to implement insertion in a singly


linked list.
#include<iostream>
using namespace std;
struct node
{
int info;
node *ptr;
};
node *head,*start,*temp;
void create(int n)
{
head=new node;
head->info=n;
if(start==NULL)
{
start=temp=head;
}
else
{
temp->ptr=head;
temp=head;
}
}
void display()
{
temp=start;
while(temp!=NULL)
{
cout<<temp->info<<endl;
temp=temp->ptr;
}
}
void insertt(int n,int loc)
{
temp=start;
for(int i=0;i<loc-1;i++)
temp=temp->ptr;
head=new node;
head->info=n;
head->ptr=temp->ptr;
temp->ptr=head;
cout<<"Modified linked list is:\n";
display();
}
int main()
{
int n,ch,m,l;
ch=1;
while(ch)
{
cout<<"Enter value to store"<<endl;
cin>>n;
create(n);
cout<<"Want to create more :0 or 1\n";
cin>>ch;
}

cout<<"Enter value to insert and position :";


cin>>m>>l;
insertt(m,l);

Q6.Write a program to implement


1. Swap consecutive nodes
2. Swap non-consecutive nodes
#include<iostream>
using namespace std;
struct node
{
int info;
node *ptr;
};
node
*head,*start,*temp,*save,*link,*c,*current,*prev,*next;
void create(int n)
{
head=new node;
head->info=n;
if(start==NULL)
{
start=temp=head;
}
else
{
temp->ptr=head;
temp=head;
}
}
void display()
{
temp=start;
while(temp!=NULL)
{
cout<<temp->info<<endl;
temp=temp->ptr;
}
}
void swapp(int n)
{ save=head=temp=start;
for(int i=0;i<n-1;i++)
{
save=head;
head=temp;
temp=temp->ptr;
}
save->ptr=temp;
head->ptr=temp->ptr;
temp->ptr=head;
cout<<"Linked list with swapped n & n-1 element is";
display();
}
void swapp(int m,int n)
{ int i;
c=link=temp=save=head=start;
for( i=0;i<m-1;i++)
{
save=head;
head=head->ptr;
}
for(i=0;i<n;i++)
{ link=temp;
temp=c;
c=temp->ptr;
}
save->ptr=temp;
temp->ptr=head->ptr;
link->ptr=head;
head->ptr=c;
cout<<"Linked list with swapped m & n element is";
display();
}
int main()
{
int n,ch,m;
ch=1;
while(ch)
{
cout<<"Enter value to store"<<endl;
cin>>n;
create(n);
cout<<"Want to create more :0 or 1\n";
cin>>ch;
}

cout<<"\nWant to swap value n with n-1 (0 or 1)\n";


cin>>ch;
if(ch==1)
{
cout<<"Enter n";
cin>>m;
swapp(m);

}
cout<<"\nWant to swap non consecutive\n";
cin>>ch;
if(ch==1)
{
cout<<"Enter m and n";
cin>>m>>n;
swapp(m,n);
}
}
Q7.Write a program to split a linked list into even and
odd linked lists.

#include<iostream>
using namespace std;
struct node
{
int info;
node *ptr;
};
node
*head,*start,*temp,*starteven,*startodd,*tempeven,*te
mpodd,*heade,*heado;
void create(int n)
{
head=new node;
head->info=n;
if(start==NULL)
{
start=temp=head;
}
else
{
temp->ptr=head;
temp=head;
}
}
void display(node *start,node *temp)
{
temp=start;
while(temp!=NULL)
{
cout<<temp->info<<endl;
temp=temp->ptr;
}
}
void splitt()
{ cout<<"split started";
temp=start;
if(temp==NULL)
cout<<"Underflow";
else
{
while(temp!=NULL)
{
if(temp->info%2==0)
{
heade=temp;
if(starteven==NULL)
{
starteven=tempeven=heade;
}
else
{
tempeven->ptr=heade;
tempeven=heade;

}
}
else
{
heado=temp;
if(startodd==NULL)
{
startodd=tempodd=heado;
}
else
{
tempodd->ptr=heado;
tempodd=heado;

}
}
temp=temp->ptr;
}
cout<<"\nLinked list with even no. is\n";
display(starteven,tempeven);
cout<<"\nLinked list with odd no, is\n";
display(startodd,tempodd);
}}
int main()
{
int n,ch,m;
ch=1;
while(ch)
{
cout<<"Enter value to store"<<endl;
cin>>n;
create(n);
cout<<"Want to create more :0 or 1\n";
cin>>ch;
}
cout<<"\nValues in linked list are\n";
display(start,temp);
splitt();
}

Q.8-Write a program to reverse a linked list.


Ans.
#include<iostream>
using namespace std;
void display(void);
void create(int);
void revers(void);
struct node
{
int info;
node *next;
};
struct node *start,*temp,*current,*ptr,*pre,*nxt;
void create(int n)
{
ptr=new node;
ptr->info=n;

if(start==NULL)
{
start=temp=ptr;
}
else
{
pre=temp;
temp->next=ptr;
temp=ptr;
temp->next=NULL;
}
}

void display()

{ temp=start;
while(temp!=NULL)
{
cout<<temp->info<<endl;
temp=temp->next;
}
}
void revers()
{
temp=start;
nxt=NULL;
pre=NULL;
while(temp!=NULL)
{

nxt=temp->next;
temp->next=pre;
pre = temp;
temp=nxt;

}
start=pre;

display();

int main()
{
int num,loc,y,c;
cout<<"press 1 for continue & 0 for exit \n";
cout<<"enter ur choice \n";
cin>>y;
while(y==1)
{
cout<<"enter the information \n";
cin>>num;
create(num);
cout<<"enter ur choice \n";
cin>>y;
}
display();
cout<<"list after reverse \n";
revers();

Q.9-Write a program to concatenate two link list.


Ans.
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct Node
{
int info;
Node*next;
}*save,*ptr,*newptr,*newptr1,b,b1;
Node *start=NULL;
Node*head=NULL;

void display(Node*);
void display(Node*);
void insert(Node*);
void concat(Node*,Node*);
int main()
{
int i,j,k,p,q;
char ch='y';
cout<<"\nNODE1\n";
while(ch=='y'|| ch=='Y')
{
cout<<"\nEnter the info:";
cin>>b.info;
newptr=(Node*)malloc(sizeof(Node));

if(newptr==NULL)
cout<<"\nNode cannot be created\n";
else
cout<<"\nNode created\n";
newptr->info=b.info;
newptr->next=NULL;
cout<<"\nInsert new node at beginning\n";
if(start==NULL)
start=newptr;
else
{
save=start;
start=newptr;
newptr->next=save;
}
cout<<"\nWant to enter more elements,press y or
Y:";
cin>>ch;
}
cout<<"\nNODE2\n";
ch='y';
while(ch=='y'|| ch=='Y')
{
cout<<"\nEnter the info:";
cin>>b1.info;
newptr1=(Node*)malloc(sizeof(Node));

if(newptr1==NULL)
cout<<"\nNode cannot be created\n";
else
cout<<"\nNode created\n";
newptr1->info=b1.info;
newptr1->next=NULL;
cout<<"\nInsert new node at beginning\n";
if(head==NULL)
head=newptr1;
else
{
save=head;
head=newptr1;
newptr1->next=save;
}
cout<<"\nWant to enter more elements,press y or
Y:";
cin>>ch;
}
display(newptr);
display(newptr1);
concat(newptr,newptr1);
}
void display(Node*newptr)
{
cout<<"\nDISPLAY\n";
if(newptr==newptr1)
newptr=head;
else
newptr=start;

while(newptr!=NULL)
{
cout<<newptr->info<<"->";
newptr=newptr->next;
}
}

void concat(Node*newptr,Node*newptr1)
{
newptr1=head;
newptr=start;
while(newptr->next!=NULL)
{
newptr=newptr->next;
}
newptr->next=head;

display(newptr);
}

Q.10-Frequency of an element in linked list.


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
struct Node
{
int info;
Node*next;
}*save,*ptr,*newptr,b;
Node *start=NULL;
Node*create_node(int);
void display(Node*);
void insert(Node*);
void freq(Node*);
int main()
{
int i,j,k,p,q;
char ch='y';
while(ch=='y'|| ch=='Y')
{
cout<<"\nEnter the info:";
cin>>b.info;
newptr=(Node*)malloc(sizeof(Node));

if(newptr==NULL)
cout<<"\nNode cannot be created\n";
else
cout<<"\nNode created\n";
newptr->info=b.info;
newptr->next=NULL;
cout<<"\nInsert new node at beginning\n";
if(start==NULL)
start=newptr;
else
{
save=start;
start=newptr;
newptr->next=save;
}
cout<<"\nWant to enter more elements,press y or
Y:";
cin>>ch;
}
freq(newptr);

return 0;

}
void display(Node*newptr)
{

cout<<"\nDISPLAY\n";
newptr=start;
while(newptr!=NULL)
{
cout<<newptr->info<<"->";
newptr=newptr->next;
}
}
void freq(Node*newptr)
{
int c=0;
newptr=start;
ptr=newptr;
while(ptr!=NULL)
{
save=(Node*)malloc (sizeof(Node));
save=newptr->next;

newptr=start;
while(newptr!=NULL)
{
if(ptr->info==newptr->info)
c++;
newptr=newptr->next;
}

cout<<"\nThe frequency of "<<ptr->info<<" is "<<c;

c=0;
newptr=save;
ptr=(Node*)malloc (sizeof(Node));
ptr=save;
}
}

Q.11-Write a program to perform delete operation in


linked list.
Ans.
#include<iostream>
using namespace std;
struct node
{
int info;
node *next;
};
struct node *start,*temp,*head,*ptr,*pre;
void create(int n)
{
ptr=new node;
ptr->info=n;

if(start==NULL)
{
start=temp=ptr;
}
else
{
temp->next=ptr;
temp=ptr;
}
}
void display()

{
temp=start;
while(temp!=0)
{
cout<<temp->info<<endl;
temp=temp->next;
}

}
void del(int a)
{ pre=NULL;
temp=start;
for(int i=1;i<a-1;i++)
{
temp=temp->next;
}
pre=temp;
ptr=temp->next;
temp=ptr->next;
pre->next=temp;

delete []ptr;
display();
}

int main()
{
int num,loc,y,c;
cout<<"press 1 for continue & 0 for exit \n";
cout<<"enter ur choice \n";
cin>>y;
while(y==1)
{
cout<<"enter the information \n";
cin>>num;
create(num);
cout<<"enter ur choice \n";
cin>>y;
}temp->next=0;
display();
cout<<"enter the location and value \n";
cin>>loc;
del(loc);
}
SPARSE MATRICES
Q1. Write a program to enter and display sparse matrix.

Ans.
#include<iostream>
using namespace std;
int main()
{
int i,j,a[10][10],n,m,l,k=1;
cout<<"entr the row and column\n";
cin>>n>>m;
cout<<"enter the element of matrix\n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cin>>a[i][j];
}
}
cout<<" your sparse matric is \n";
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<a[i][j];
}
cout<<"\n";
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]!=0)
{
m[k][0]=i;
m[k][1]=j;
m[k][2]=a[i][j];
k++;
l++;
}
}
}
m[0][0]=n;
m[0][1]=m;
m[0][2]=l;
cout<<"3 column representation is \n";
for(i=0;i<k;i++)
{
for(j=0;j<k;j++)
{
cout<<m[i][j];
}
cout<<"\n";
}
}

Q2.-Write a program to transpose a sparse matrix.


Ans.
#include<stdio.h>
#include<iostream>
using namespace std;
class sparse
{public:
int rows;
int columns;
int value;
int a[10][3];
int t;
int input()
{
int s=0;
t=0;
char ch;
cout<<"\nEnter the number of rows:";
cin>>rows;
cout<<"\nEnter the number of columns:";
cin>>columns;
do{
cout<<"\nEnter the elements in triple form";
cin>>a[s][0]>>a[s][1]>>a[s][2];
cout<<"\nWant to enter more non zero elements?(y
or n)";
cin>>ch;
s++;
t++;
}while(ch=='y');
}
int spar()
{
int s=0;
cout<<"\nSparse matrix obtained:\n";
for(int i=0;i<rows;i++)
{
for(int j=0;j<columns;j++)
{
if((a[s][0]==i) && (a[s][1]==j))
{
cout<<a[s][2];

s=s+1;

else
cout<<0;

cout<<endl;
}
}
};

int main()
{
int k;
int p;
int c[10][3];
sparse b[2];
int x;
b[0].input();

b[0].spar();

if((b[0].t)>(b[1].t))
k=b[0].t;
else
k=b[1].t;

int s=0;
int z=0;
int f=0;
cout<<endl<<endl;

cout<<"\nTranspose of first matrix:\n";


for(int i=0;i<b[0].t;i++)

{
x=b[0].a[i][1];
b[0].a[i][1]=b[0].a[i][0];
b[0].a[i][0]=x;
}

cout<<endl<<"Matrix after transpose:\n";


int q=0;
for(int i=0;i<b[0].rows;i++)
{
for(int j=0;j<b[0].columns;j++)
{
if(b[0].a[q][0]==i && b[0].a[q][1]==j)
{

cout<<b[0].a[q][2];
q++;
}
else
cout<<0;

}
cout<<endl;
}
}

Q.3-Write a program to perform multiplication of two


sparse matrices.
Ans.
#include<stdio.h>
#include<iostream>
using namespace std;
class sparse
{public:
int rows;
int columns;
int value;
int a[10][3];
int t;
int input()
{
int s=0;
t=0;
char ch;
cout<<"\nEnter the number of rows:";
cin>>rows;
cout<<"\nEnter the number of columns:";
cin>>columns;
do{
cout<<"\nEnter the elements in triple form";
cin>>a[s][0]>>a[s][1]>>a[s][2];
cout<<"\nWant to enter more non zero elements?
(y or n)";
cin>>ch;
s++;
t++;
}while(ch=='y');
}
int spar()
{
int s=0;
cout<<"\nSparse matrix obtained:\n";
for(int i=0;i<rows;i++)
{
for(int j=0;j<columns;j++)
{
if((a[s][0]==i) && (a[s][1]==j))
{
cout<<a[s][2];
s=s+1;
}
else
cout<<0;

}
cout<<endl;
}
}
};

int main()
{
int k;
int p;
int c[10][3];
sparse b[2];
int x;
b[0].input();
b[1].input();
b[0].spar();
b[1].spar();
if((b[0].t)>(b[1].t))
k=b[0].t;
else
k=b[1].t;
int s=0;
int z=0;
cout<<endl<<endl;
if(b[0].columns==b[1].rows)
cout<<"\nMULTIPLICATION POSSIBLE\n";
else
cout<<"\nMULTIPLICATION NOT POSSIBLE\n";
for(int i=0;i<b[0].rows;i++)
{
for(int j=0;j<b[1].columns;j++)
{
int sum=0;
for(int m=0;m<b[0].columns;m++)
{
if((b[0].a[z][0]==i && b[0].a[z][1]==m) &&
(b[1].a[z][0]==m && b[1].a[z][1]==j))
{
sum=sum+b[0].a[z][2]*b[1].a[z][2];
z++;
}

}
cout<<sum;
}
cout<<endl;
}
}

You might also like