answersLogoWhite

0

void main()

{

int a[10][10],b[10][10],c[10][10],i,j,k,m,n,p,q;

printf("Enter The Rows And Cloumns And Of The First Matrix:");

scanf("%d %d",&m,&n);

printf("\nEnter The Rows And Cloumns And Of The Second Matrix:");

scanf("%d %d",&p,&q);

printf("\nEnter Elements Of The First Matrix:\n");

for(i=0;i< m;i++)

{

for(j=0;j< n;j++)

{

scanf("%d",&a[i][j]);

}

}

printf("\nEnter Elements Of The Second Matrix:\n");

for(i=0;i< p;i++) {

for(j=0;j< q;j++)

scanf("%d",&b[i][j]);

}

printf("The First Matrix Is:\n"); /* Print the first matrix */

for(i=0;i< m;i++) {

for(j=0;j< n;j++)

printf(" %d ",a[i][j]);

printf("\n");

}

printf("The Second Matrix Is:\n"); /* Print the second matrix */

for(i=0;i< p;i++) {

for(j=0;j< q;j++)

printf(" %d ",b[i][j]);

printf("\n");

}

if(n!=p) {

printf("Aborting./nMultiplication Of The Above Matrices Not Possible.");

exit(0);

}

else {

for(i=0;i< m;i++) {

for(j=0;j< q;j++) {

c[i][j] = 0;

for(k=0;k< n;k++) {

c[i][j] = c[i][j] + a[i][k] * b[k][j];

}

}

}

printf("\nThe Product Of The Two Matrices Is:\n\n");

for(i=0;i< m;i++) {

for(j=0;j< q;j++) {

printf(" %d ",c[i][j]);

}

printf("\n");

}

}

return 0;

}

-----------------------------------------------------">-----------------------------------------------------

The above code is not the solution of Matrix multiplication using pointers.

the following code is absolutely correct.

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

{

for(j=0;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

{

printf("\n");

for(j=0;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

{

for(j=0;j

{

*(z+i*c2+j)=0;

for(k=0;k

{

*(z+i*c2+j)+=*(p+k*2+j)*(*(q+i*c2+k));

}

}

}

}

//Designed by Asjad Farrukh.......

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

Can you swap two matrix?

Provided both matrices are mutable, two matrices A and B can be swapped like any other two items: create temporary storage to store a copy of A, then assign B to A, and finally assign the temporary copy of the previous version of A to B. Note that in the C programming language, matrices cannot be assigned to each as such. One implementation of this algorithm might operate on the basis of references (pointers), and can thus swap two matrix references by swapping two pointers in the manner detailed above. Implementations wishing to actually transfer the data held in one matrix to another would use a library function such as memcpy() to transfer data.


What are function pointers?

Function Pointers are basically used when we want to select a function which is to be used dynamically at run time.AnswerFunction pointers are the only way for "Interept programming". In UNIX all the Interepts are called using function pointers. This is mainly used in system programming. Answerits nothing but a pointer to function. which is similar to ptr to a variable, if we are saying ptr to a variable then it will hold address of the variable like that fn. ptr will have the address of the function.. one of the major application of the function pointer is call back function.. i.e callback.AnswerPointers to functions/methods/subroutines aka 'Delegates' are frequently used in .NET programming especially in EventHandling, MemberInvoking A function pointer is used to pass a function as an argument to another function, or to store a function as a data item, for example a list of functions can be implemented as an array of pointers to functions. Function pointers are used to store interrupt handlers in tables.


How to multiply two int pointer variable in C language?

You do not multiply pointers. If you want to multiply the values that they point to you must dereference them, usually with a *


Function prototype in c?

Yes. Examples can be found in stdio.h


Is Use of pointers in function saves the memory space?

No. But avoiding unnecessary duplication of data does.

Related Questions

What is meant by passing function to another function in c plus plus?

Just as pointers can point to variables, pointers can also point to functions. Thus you can pass function pointers to functions. In so doing, you can alter the behaviour of the function by having it call dynamically call arbitrary functions rather than just preset functions.


What is virtual function table?

A virtual function table is a table of pointers to functions.


Where are array of functions used?

Function Pointers are basically used when we want to select a function which is to be used dynamically at run time.


What are functions and pointers in c?

function-these are self contained block of statements to solve a particular task whereas pointers are defined as the variable which stores the address of another variable


Pointers to review in a napolcom examination?

government functions


Can functions be defined in C structures?

No, all functions must be defined outside of C structures. However, all functions in C have a type (the return type) and an identity (an address), so you can define function pointers as members of a structure to achieve the same end.


Multiply two matrics using pointer?

To multiply two matrices using pointers in C, you can create a function that takes pointers to the matrices and their dimensions as parameters. Use nested loops to iterate through the rows of the first matrix and the columns of the second matrix, calculating the dot product for each element in the resulting matrix. Store the results in a dynamically allocated array, ensuring to properly manage memory. Here's a brief code snippet to illustrate the concept: void multiplyMatrices(int *A, int *B, int *C, int rowsA, int colsA, int colsB) { for (int i = 0; i &lt; rowsA; i++) { for (int j = 0; j &lt; colsB; j++) { C[i * colsB + j] = 0; // Initialize the result element for (int k = 0; k &lt; colsA; k++) { C[i * colsB + j] += A[i * colsA + k] * B[k * colsB + j]; } } } }


Can you swap two matrix?

Provided both matrices are mutable, two matrices A and B can be swapped like any other two items: create temporary storage to store a copy of A, then assign B to A, and finally assign the temporary copy of the previous version of A to B. Note that in the C programming language, matrices cannot be assigned to each as such. One implementation of this algorithm might operate on the basis of references (pointers), and can thus swap two matrix references by swapping two pointers in the manner detailed above. Implementations wishing to actually transfer the data held in one matrix to another would use a library function such as memcpy() to transfer data.


What are function pointers?

Function Pointers are basically used when we want to select a function which is to be used dynamically at run time.AnswerFunction pointers are the only way for "Interept programming". In UNIX all the Interepts are called using function pointers. This is mainly used in system programming. Answerits nothing but a pointer to function. which is similar to ptr to a variable, if we are saying ptr to a variable then it will hold address of the variable like that fn. ptr will have the address of the function.. one of the major application of the function pointer is call back function.. i.e callback.AnswerPointers to functions/methods/subroutines aka 'Delegates' are frequently used in .NET programming especially in EventHandling, MemberInvoking A function pointer is used to pass a function as an argument to another function, or to store a function as a data item, for example a list of functions can be implemented as an array of pointers to functions. Function pointers are used to store interrupt handlers in tables.


How to multiply two int pointer variable in C language?

You do not multiply pointers. If you want to multiply the values that they point to you must dereference them, usually with a *


What is the difference between pointer and function?

Pointers and functions are two entirely different things, similar to comparing cats to oranges. A pointer allows a program to dynamically call functions and/or dynamically load or store data. Pointers are commonly called "dangerous" in most programming circles, which is why newer languages do not explicitly allow programmers to access them (although they may use them internally). They are dangerous because a pointer used incorrectly can corrupt data or crash a system (or at least an application). While this is true, they are not dangerous by themselves, it is the novice programmer's misunderstanding of pointers that is dangerous. Functions are pieces of code that can be used over and over again in various parts of a program without duplicating code. For example, a function that calculates simple interest might be used in several parts of a banking application. This way, if a bug was found in how simple interest was calculated, it could be fixed just once instead of scanning the entire code base to make sure it was fixed everywhere. Functions reduce source code size, executable size, and memory usage. Pointers can dynamically call functions, while functions are pieces of code that can execute. Functions have no concept of pointers, and do not care from where they are called.


Function prototype in c?

Yes. Examples can be found in stdio.h