hello,
Code:
#include <conio.h>
#include <time.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
//freopen("conventionInput.txt","r",stdin);
long long m1[5][100],i,j,k,m2[100][5],mult[100][100],r1,c1,r2,c2;
char Manual = 'N';
printf("Enter Matrix Input Manually? (Y/N)\n");
Manual = getchar();
Manual = toupper(Manual);
printf("Enter variable Y MIN 32 MAX 100\n");
scanf("%lld",&c1);
r2 = c1;
r1 = 5;
c2 = 5;
/* initialize random seed: */
srand ( time(NULL) );
/* generate secret number: */
if(r2==c1)
{
printf("Enter rows and columns of First matrix \n");
printf("Row wise\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++){
if(Manual == 'Y')
scanf("%lld",&m1[i][j]);
else
m1[i][j] = rand() % 10 + 1;
}
}
printf("You have entered the first matrix as follows:\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
printf("%lld\t",m1[i][j]);
printf("\n");
}
printf("Enter rows and columns of Second matrix \n");
printf("Again row wise\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++){
if(Manual == 'Y')
scanf("%lld",&m2[i][j]);
else
m2[i][j] = rand() % 10 + 1;
}
}
printf("You have entered the second matrix as follows:\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
printf("%lld\t",m2[i][j]);
printf("\n");
}
printf("Now we multiply both the above matrix. Clock Time will start here \n");
printf("The result of the multiplication is as follows:\n");
//a11xA11+a12xA21+a13xA31 a11xA12+a12xA22+a13xA32 a11xA13+a12xA23+a13xA33
clock_t start = clock();
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
mult[i][j]=0;
for(k=0;k<r1;k++)
{
mult[i][j]+=m1[i][k]*m2[k][j];
mult[0][0]=m1[0][0]*m2[0][0]+m1[0][1]*m2[1][0]+m1[0][2]*m2[2][0];
}
printf("%lld\t",mult[i][j]);
}
printf("\n");
}
printf("Time elapsed: %f ms \n", ((double)clock() - start) / CLOCKS_PER_SEC);
getch();
}
else
{
printf("Matrix multiplication cannot be done");
}
}
My problem now is this matrix multiplication coding not give the actual result after..can u check which part that cause this problem..
tq.