By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,261 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

please help me to fix this code. i am trying to write a program in C that takes in t

P: 1
And this what i wrote:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2.  
  3. void printMatrix(int row, int col, float m[row][col]);
  4. float calcEntry(float x[], float y[]);
  5. int main(voide)
  6. {
  7.     int r1,r2,c1,c2,i,j,k;
  8.     float mult[10][10],A[10],B[10];
  9.  
  10.     printf("Enter Row and Column for Matrix1:");
  11.     scanf("%d%d",&r1,&c1);
  12.     printMatrix(r1,c1);
  13.     printf("Emter Row and Column for Matrix2:");
  14.     scanf("%d%d",&r2,&c2);
  15.     printMatrix(r2,c2);
  16.  
  17.     while (c1!=r2) {
  18.         printf("Error! Column of Matrix1 not equal to Rowof Matrix2:\n");
  19.         printf("\n please Enter Column and Row for Matrix1:");
  20.         scanf("%d%d",&r1,&c1);
  21.         printf("Enter Column ans Row for Mtrix2:");
  22.         scanf("%d%d",&r2,&c2);
  23.  
  24.     }
  25.  
  26.     printf("\nEnter elements of matrix 1:\n");
  27.  
  28.     for (i=0; i<r1; ++i)
  29.     for (j=0; j<c1; ++j)
  30. {
  31.     printf("Enter elements A%d%d:", i+1,j+1);
  32.             scanf("%f", &A[i][j]);
  33.         }
  34.     printf("\nEnter elements of matrix 2:\n");
  35.              for(i=0; i<r2; ++i)
  36.              for(j=0; j<c2; ++j)
  37.         {
  38.             printf("Enter elements B%d%d: ",i+1,j+1);
  39.             scanf("%f",&B[i][j]);
  40.         }
  41.     for (i=0; i<r1; ++i)
  42.     for (j=0;j<c2;++j)
  43.     for(k=0;k<c1;++k)
  44.     {
  45.         mult[i][j]+=A[i][k]*B[k][j];
  46.  
  47.     }
  48.     printf("\nOutput Matrix:\n");
  49.     for(i=0;i<r1;++i)
  50.         for(j=0;j<c2;++j)
  51.         {
  52.             printf("%f", mult[i][j]);
  53.             if(j==c2-1)
  54.                 printf("\n\n");
  55.         }
  56.  
  57.     return 0;
  58.  
  59. }
Nov 21 '15 #1
Share this Question
Share on Google+
1 Reply


zmbd
Expert Mod 5K+
P: 5,380
sahafiza:

Please explain what your issue is with the code.
As you can see, the title isn't a good place to put the actual question do to the size limit.
home > faq > how to post and answer questions on bytes

IF you can post a clear question that explains what it is that you are attempting, contains any error messages (detailed please), and what it is you are attempting to accomplish - it would be my pleasure to merge that post into your original post. :-)


+ We also ask that you use your debugger to step thru the code to determine which line may be causing the issues. It's really not fair to ask our members to do the basic trouble-shooting that could be accomplished by this step. :-)

Also, when posting script, pleas use the [CODE/] format tool in the post toolbar.

:)
Nov 21 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.