J
John Doe
segmentation error !!!!
hi guys ,
i wrote this program to multiply two matrices (just the basic code
without checkin 4 the condition n==p )
"
#include<stdio.h>
main()
{
int a[10][10],b[10][10],c[10][10];
int m,n,p,q,i,j,k;
printf("Enter the size of the first array A:");
scanf("%d %d",&m,&n);
printf("Enter the size of the second array A:");
scanf("%d %d",&p,&q);
printf("\nEnter the value of the Matrix A:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("\nEnter the value:");
scanf("%d",a[j]);
}
printf("\nEnter the value of the Matrix B:\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
{
printf("\nEnter the value:");
scanf("%d",b[j]);
}
/* MULTIPLICATION */
for(i=0;i<m;i++)
for(j=0;j<q;j++)
{
c[j]=0;
for(k=0;k<n;k++)
c[j]+=(a[k]*b[k][j]);
}
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<q;j++)
printf("%d \t",c[j]);
}
}
"
i compiled this code using gcc compiler.... no errors showed up ...
then i executed ...this is what i got ....
"
Enter the size of the first array A:2
2
Enter the size of the second array A:2
2
Enter the value of the Matrix A:
Enter the value:2
Segmentation fault
"
can u guys please tell me what this segementation error is ..?
and y it was thrown up suddenly in my program ,,?
i've never encountered this error before ...
hi guys ,
i wrote this program to multiply two matrices (just the basic code
without checkin 4 the condition n==p )
"
#include<stdio.h>
main()
{
int a[10][10],b[10][10],c[10][10];
int m,n,p,q,i,j,k;
printf("Enter the size of the first array A:");
scanf("%d %d",&m,&n);
printf("Enter the size of the second array A:");
scanf("%d %d",&p,&q);
printf("\nEnter the value of the Matrix A:\n");
for(i=0;i<m;i++)
for(j=0;j<n;j++)
{
printf("\nEnter the value:");
scanf("%d",a[j]);
}
printf("\nEnter the value of the Matrix B:\n");
for(i=0;i<p;i++)
for(j=0;j<q;j++)
{
printf("\nEnter the value:");
scanf("%d",b[j]);
}
/* MULTIPLICATION */
for(i=0;i<m;i++)
for(j=0;j<q;j++)
{
c[j]=0;
for(k=0;k<n;k++)
c[j]+=(a[k]*b[k][j]);
}
for(i=0;i<m;i++)
{
printf("\n");
for(j=0;j<q;j++)
printf("%d \t",c[j]);
}
}
"
i compiled this code using gcc compiler.... no errors showed up ...
then i executed ...this is what i got ....
"
Enter the size of the first array A:2
2
Enter the size of the second array A:2
2
Enter the value of the Matrix A:
Enter the value:2
Segmentation fault
"
can u guys please tell me what this segementation error is ..?
and y it was thrown up suddenly in my program ,,?
i've never encountered this error before ...