ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Do you have a collection of Interview Questions and interested to share with us!!
Please send that collection to along with your userid / name. ThanQ
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
write a program in c language for the multiplication of two 
matrices using pointers?
 Question Submitted By :: Sbabli90
I also faced this Question!!     Rank Answer Posted By  
 
  Re: write a program in c language for the multiplication of two matrices using pointers?
Answer
# 1
main()
{
int mat1[3][3] = {1,2,3,4,5,6,7,8,9};
int mat2[3][3] = {1,2,3,4,5,6,7,8,9};
int res[3][3];
int i,j,k;
for (i=0; i<3; i++)
for (j=0; j<3; j++)
res[i][j] = 0;
for (i=0; i<3; i++)
for (j=0; j<3; j++)
for (k=0; k<3; k++)
*(*(res + i) + j) += (*(*(mat1 + i) + k)) * (*(*(mat2 + k) 
+ j));

for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
printf ("%d\t", res[i][j]);
printf ("\n");
}
printf("\n");
}
 
Is This Answer Correct ?    39 Yes 13 No
Syed Fakheruddin Ahmad
 
  Re: write a program in c language for the multiplication of two matrices using pointers?
Answer
# 2
9
 
Is This Answer Correct ?    8 Yes 12 No
Arum Kumar Mishra
 
 
 
  Re: write a program in c language for the multiplication of two matrices using pointers?
Answer
# 3
#include<stdio.h> 
#include<conio.h> 
int main() 
{ 
    int mul(int,int); 
    int n1,n2,f=1,ans; 
    while(f==1) 
    { 
        printf("\n***MULTIPLICATION OF TWO NATURAL 
NUMBERS***"); 
        printf("\nEnter Two Numbers: "); 
        scanf("%d %d",&n1,&n2); 
        if(n1<=0||n2<=0) 
        { 
            printf("\nInvalid Choice..."); 
            printf("\nDo You Want To Try 
Again...\n1.Yes\n2.No"); 
            scanf("%d",&f); 
        } 
        else 
        { 
            printf("\nAns = %d",mul(n1,n2),"\n"); 
            printf("\nDo You Want To 
Continue:\n1.Yes\n2.No\n"); 
            scanf("%d",&f); 
        } 
    } 
} 
int mul(int a,int b) 
{ 
    return((b-1)*a+a); 
}
 
Is This Answer Correct ?    4 Yes 4 No
Tutu
 
  Re: write a program in c language for the multiplication of two matrices using pointers?
Answer
# 4
#include<stdio.h>
#include<conio.h>
int main()
{
    int n,m,i,j,k;
    int a[38][38],b[38][38],p[38][38];
    printf("\nEnter the number of rows and coloumns ");
    scanf("%d %d",&n,&m);
    printf("\nEnter the elements of first matrix ");
    for(i=0;i<n;i++)
    {
                    for(j=0;j<m;j++)
                    {
                                    scanf("%d",(*(a+i)+j));
                    }
    }
    printf("\nMatrix is ");
     for(i=0;i<n;i++)
    {
                     printf("\n");
                    for(j=0;j<m;j++)
                    {
                                    printf("%d",*(*(a+i)+j));
                                    printf("\t");
                    }
    }
     printf("\nEnter the elements of second matrix ");
    for(i=0;i<n;i++)
    {
                    for(j=0;j<m;j++)
                    {
                                    scanf("%d",(*(b+i)+j));
                    }
    }
    printf("\nMatrix is ");
     for(i=0;i<n;i++)
    {
                     printf("\n");
                    for(j=0;j<m;j++)
                    {
                                    printf("%d",*(*(b+i)+j));
                                    printf("\t");
                    }
    }
    printf("\nAfter multiplication ");
    for(i=0;i<n;i++)
    {
                    for(j=0;j<m;j++)
                    {
                    p[i][j]=0;
                    for(k=0;k<n;k++)
                    {
                    p[i][j]+=a[i][k]*b[k][j];
                    }
                    }
                    }
                    for(i=0;i<n;i++)
                    {
                    printf("\n");
                    for(j=0;j<m;j++)
                    {
                    printf("%d",*(*(p+i)+j));
                    printf("\t");
                    }
                    }
                                                           
                        
    getch();
}
 
Is This Answer Correct ?    6 Yes 4 No
Ruchi
 
  Re: write a program in c language for the multiplication of two matrices using pointers?
Answer
# 5
// write a program to multipication of a matrix
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
void main()
{
int *ptr1,*ptr2,*ptr3;
int m,n,i,j,k;
printf("enter m & n=");
scanf("%d%d",&m,&n);
ptr1=(int*)malloc((m*n)*sizeof(int));
ptr2=(int*)malloc((m*n)*sizeof(int));
ptr3=(int*)malloc((m*n)*sizeof(int));
printf("enter elements of 1st matrix=");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",((ptr1+i)+j)) ;
}
}
printf("enter elements of 2nd matrix=");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",((ptr2+i)+j)) ;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
*((ptr3+i)+j)=0;
for(k=0;k<n;k++)
{
*((ptr3+i)+j)=*((ptr3+i)+j)+(*((ptr1+i)+j))*(*((ptr2+j)+k));
}
}
}
printf("multipication is=\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",*((ptr3+i)+j)) ;
}
printf("\n");
}
getch();
}
 
Is This Answer Correct ?    4 Yes 4 No
Shankey Narang
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
What's the difference between calloc() and malloc()?  3
main() { char *p1="Name"; char *p2; p2=(char *)malloc(20); while(*p2++=*p1++); printf("%s\n",p2); } CitiGroup4
Is reference used in C?  1
what is available in C language but not in C++?  1
main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); } ME3
How do I initialize a pointer to a function?  2
plz answer.... write a program that reads line (using getline) e.g."345", converts each line to an integer using "atoi" and computes the average of all the numbers read. also compute the standard deviation.  1
declare afunction pointer to int printf(char *)? HCL1
What is alloca() and why is its use discouraged?  1
I have an array of 100 elements. Each element contains some text. i want to: append a star character to the end of every fifth element remove every second character from every tenth element, and… add a line feed (ascii 10) after the 30th character of every array element whose length is greater than 30 characters.  1
a 'c' program to tell that the set of three coordinates lie on a same line Persistent1
what is the difference between #include<stdio.h> and #include "stdio.h" ?  2
if a five digit number is input through the keyboard, write a program to calculate the sum of its digits. (hint:-use the modulus operator.'%')  9
i want to have a program to read a string and print the frequency of each character and it should work in turbo c  2
write a 'c' program to sum the number of integer values  5
what is the difference between declaration and definition of a variable or function ?  2
Write code for initializing one dimentional and two dimentional array in a C Program? Deshaw5
What are volatile variables?  1
How to Clear last bit if it 1 using Macro TURN_OFF_BIT_LAST Adobe2
What is the Difference between Macro and ordinary definition? Motorola2
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com