445,778 Members | 1,957 Online
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

# segmentation error ....!

 P: n/a segmentation error !!!! hi guys , i wrote this program to multiply two matrices (just the basic code without checkin 4 the condition n==p ) " #include 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
4 Replies

 P: n/a In article <11**********************@m58g2000cwm.googlegroups .com>, John Doe int a[10][10],b[10][10],c[10][10]; [...] >scanf("%d",a[j]); a is a two-dimensional array, so you want something like &a[i][j]. You have the same problem here: >scanf("%d",b[j]); and here: >c[j]=0; and here (twice): >c[j]+=(a[k]*b[k][j]); and here: >printf("%d \t",c[j]); -- Richard -- "Consideration shall be given to the need for as many as 32 characters in some alphabets" - X3.4, 1963. Feb 20 '07 #2

 P: n/a On Feb 20, 8:51 pm, rich...@cogsci.ed.ac.uk (Richard Tobin) wrote: In article <1171985776.676322.268...@m58g2000cwm.googlegroups .com>, John Doe

 P: n/a John Doe said: segmentation error !!!! hi guys , i wrote this program to multiply two matrices (just the basic code without checkin 4 the condition n==p ) " #include 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); Check that the read succeeded. In this case, you are asking scanf to populate two objects, so it will return 2 if successful. printf("Enter the size of the second array A:"); scanf("%d %d",&p,&q); Check that the read succeeded. In this case, you are asking scanf to populate two objects, so it will return 2 if successful. Now would be a good point at which to make sure that none of i, j, m, and n exceed 10. (At first, I thought this was probably causing your problem, but then I discovered that your test data comprises 2, 2, 2, 2, so let's move on.) printf("\nEnter the value of the Matrix A:\n"); for(i=0;i

 P: n/a In article <11**********************@m58g2000cwm.googlegroups .com"John Doe"

### This discussion thread is closed

Replies have been disabled for this discussion.