1 Replies - 310 Views - Last Post: 22 February 2017 - 07:03 AM Rate Topic: -----

#1 vibhujainmj   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 22-February 17

it is showing error invalid direction can u help me out

Posted 22 February 2017 - 04:03 AM

#include<iostream.h>
#include<process.h>
#include<conio.h>
int main()
{
clrscr();
int in[10],b[10],c[10];
int i,j,m,n,p,q;
cout<<"\nInput row & column of matrix-A\n";
cin>>m>>n;
cout<<"\nInput row & column of matrix-B\n";
cin>>p>>q;
if((m==p)&&(n==q))
cout<<"Matrix can be added"<<endl;
else
{
cout<<"Matrix cannot be added"<<endl;
exit(0);
}
cout<<"Enter matrix-A"<<endl;
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
cin>>in[i][j];
}
cout<<"Mintrix-A"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<" "<<in[i][j];
}
cout<<"Enter mintrix-B"<<endl;
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
cin>>b[i][j];
}
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
c[i][j]=in[i][j]+b[i][j];
}
cout<<"The sum of 2 mintrices is:"<<endl;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cout<<" "<<c[i][j];
}
return 0;
}

This post has been edited by snoopy11: 22 February 2017 - 07:12 AM
Reason for edit:: added [ CODE ] tags please learn to use them !


Is This A Good Question/Topic? 0
  • +

Replies To: it is showing error invalid direction can u help me out

#2 r.stiltskin   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2032
  • View blog
  • Posts: 5,435
  • Joined: 27-December 05

Re: it is showing error invalid direction can u help me out

Posted 22 February 2017 - 07:03 AM

It's invalid indirection.

You declared each of your arrays in, b and c as 1-dimensional int arrays, but then in your for loops you address all of them as if they were 2-dimensional arrays.

Another potential source of trouble is that the sizes of the arrays is fixed, but then you allow the user to enter the sizes of the rows and columns. You should add code to ensure that the values entered for m, n, p, and q are no greater than 10 to avoid going outside the bounds of the arrays.

In the future when you post code please use code tags. Read the instructions printed in faint text in the posting window.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1