write a program in c language for the multiplication of two
matrices using pointers?

Answer Posted / asjad farrukh

void main()
{int *a,*b,*c,row1,col1,row2,col2;
clrscr();
printf("enter rows of 1at matrix");
scanf("%d",&row1);
printf("enter columns of 1at matrix");
scanf("%d",&col1);
printf("enter rows of 2nd matrix");
scanf("%d",&row2);
printf("enter columns of 2nd matrix");
scanf("%d",&col2);
if(col1!=row2)
{
printf("\nsorry\n");
}
else
{
a = (int *) malloc(row1*col1 * 2);
b = (int *) malloc(row2*col2 * 2);
c = (int *) malloc(col1*row2 * 2);

clrscr();
printf("enter 1st matrix \n");
insert(a,row1,col1);
getch();
clrscr();
printf("enter 2st matrix \n");
insert(b,row2,col2);
getch();
clrscr();
printf("1st matrix is\n");
display(a,row1,col1);
printf("\n2nd matrix is\n");
display(b,row2,col2);
prod(a,b,c,row1,col2);
printf("\nafter multiplication \n\n\n");
display(c,row1,col2);
}
getch();
}
insert(int *q,int r,int c)
{int i,j;
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{ printf("\nEnter [%d][%d] element-- ",i,j);
scanf("%d",(q+i*c+j));
}
}
}

display(int *q,int r,int c)
{int i,j;
for(i=0;i<r;i++)
{
printf("\n");
for(j=0;j<c;j++)
{
printf("%d\t",*(q+i*c+j));
}
}
}
prod(int *p,int *q,int *z,int r1,int c2)
{int i,j,k;
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
*(z+i*c2+j)=0;
for(k=0;k<r1;k++)
{
*(z+i*c2+j)+=*(p+k*2+j)*(*(q+i*c2+k));
}
}

}
}

Is This Answer Correct ?    7 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

A set of N billiard balls are set on a one-dimensional table. The table is 1 meter long, set north-south with two pockets at either side. Each ball has zero width and there is no friction so it is moving with a fixed velocity of either northward or southward and bounces back in a perfect elastic collision from other balls it encounter on its way (or drop into one of the pockets). Your job is to keep track of the balls movements. Task Please write a program that gets the initial place, speed and direction of all the balls and gives the position of a specific ball after t seconds. Input The first line contains the number of scenarios. Each one of the other lines in the input contains a scenario: The first number, N, is the number of balls; followed by N pairs of numbers: the distance in centimeters from the south end of the table and the speed (positive speed meaning it moves northward); the last two numbers are the number i of the target ball you should track and the time T in seconds. Output The output is a single number for each line which is the place (distance in centimeters from the south end of the table) of the tracked ball after T seconds. Note: There is no new line character at the end of the result. Sample Input 5 1 50 1 1 1000 1 50 1 1 6 1 60 -2 1 6 2 10 1 95 -1 2 30 2 10 1 95 -1 2 60 Sample Output 100 56 48 65 70

2137


What is the difference between exit() and _exit() function?

610


the constant value in the case label is followed by a a) semicolon b) colon c) braces d) none of the above

726


What are two dimensional arrays alternatively called as?

669


What is integer constants?

626






What is the function of this pointer?

681


What is the use of bitwise operator?

694


What do you mean by scope of a variable in c?

548


Do you have any idea how to compare array with pointer in c?

611


Iam a B.Tech graduate and completed my engineering in 2009, from 2005 to 2009 and after that i had done nothing.Now i want to do job and get into BPO field . Friends give me suggestions as what to say in interview... if they ask me that what would you had done ... these many years without doing job ??????? pls urgent

1432


Can we compile a program without main() function?

637


The statement, int(*x[]) () what does in indicate?

649


How can a program be made to print the name of a source file where an error occurs?

735


Is c call by value?

613


Is it acceptable to declare/define a variable in a c header?

688