Programs not running
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
int a[100][100],b[100][100],ar,ac,br,bc,i,j,k;
int sum[100][100],diff[100][100],prod[100][100];
clrscr();
cout<<"Enter number of rows and columns for A ";
cin>>ar>>ac;
cout<<"\nEnter number of rows and columns for B ";
cin>>br>>bc;
if((ar!=br)||(ac!=bc))
{
cout<<"\nAddition and Subtraction not possible";
goto stop1;
}
cout<<"\nEnter the Elements of A\n";
for(i=0;i<ar;i++)
{
for(j=0;j<ac;j++)
{
cin>>a[i][j];
}
cout<<"\n";
}
cout<<"Enter the terms of B\n";
for(i=0;i<br;i++)
{
for(j=0;j<bc;j++)
{
cin>>b[i][j];
}
cout<<"\n";
}
for(i=0;i<ar;i++)
{
for(j=0;j<ac;j++)
{
sum[i][j]=(a[i][j] + b[i][j]);
}
cout<<"\n";
}
for(i=0;i<ar;i++)
{
for(j=0;j<ac;j++)
{
diff[i][j]=abs(a[i][j] - b[i][j]);
}
cout<<"\n";
}
cout<<"Sum of the two matrices is\n";
for(i=0;i<ar;i++)
{
for(j=0;j<ac;j++)
{
cout<<sum[i][j]<<" ";
}
cout<<"\n";
}
cout<<"\n\nDifference of the two matrices is\n";
for(i=0;i<ar;i++)
{
for(j=0;j<ac;j++)
{
cout<<diff[i][j]<<" ";
}
cout<<"\n";
}
stop1:
if(ac!=br)
{
cout<<"\n\nMultiplication not possible";
goto stop2;
}
cout<<"Product of the two matrices is\n";
for(i=0;i<ar;i++)
{
for(j=0;j<bc;j++)
{
prod[i][j]=0;
for(k=0;k<ac;k++)
{
prod[i][j]=prod[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=0;i<ac;i++)
{
for(j=0;j<br;j++)
{
cout<<prod[i][j]<<" ";
}
cout<<"\n";
}
stop2:
getch();
}
|
My problem is that I'm getting some 'Stack overfault' in module -file name- at 0002:000E. Choose close. -file name- will close.
I'm using turboc++ 4.5.
1 2
|
a[100][100],b[100][100] ...
sum[100][100],diff[100][100],prod[100][100] ...
|
These variables vill be created on stack. There is 15 000 integers. Stack just isn't lagre enough to hold it.
What do you need is to learn about dynamic memory allocation.
Topic archived. No new replies allowed.