i wann multiply two matrix but the part of given code is not working...i wanna input the value from the user using pointers..

#include<stdio.h>
#include<conio.h>
void main()

{

     printf("This is matrix multiplication program");
     printf("\nEnter the dimensions of two array ");
     int Row1 = 0, Col1 = 0, Row2 = 0, Col2 = 0;
     scanf("%d,%d,%d,%d", &Row1, &Col1, &Row2, &Col2);
     printf("\nDmensions of two arrays are Matrix1:Row1:%d ,Col1:%d \nMatrix2:Row2: %d, Col2:%d" ,Row1, Col1, Row2, Col2);
     if(Col1==Row2)
     {
                  printf("\nCompatible to multiply");
                  int Matrix1[Row1][Col1];
                  int Matrix2[Row2][Col2];
                  printf("\nEnter the value of Matrix 1");
                      
        
     

                  void value(Matrix1,Row1, Col1);
                  void value(Matrix2,Row2, Col2);                
                
                   }
                   else
                   printf("\n not a compatible type to multiply");
     getch();
     } 


     void value(int *Matrix,int a, int b)
{
         
         {
                    int i=0, j=0;
         for(i=0; i<a; i++)
           {
                 for( j=0; j<b; j++)
                 {
                        scanf("%d",(Matrix+i*b+j));
                  }
           }
        } 
     
    printf("value of Matrix1 are");
  {
  int i=0, j=0;
  for(i=0; i<a; i++)
         {
                 for(j=0; j<b; j++)
                 {
                        printf("%d",*(Matrix+i*b+j));
                 }
         }
  }


}
#include <stdio.h>

void value(int *Matrix,int a, int b);

int main(void)
{     	 
     int Row1 = 0, Col1 = 0, Row2 = 0, Col2 = 0;
     int Matrix1[10][10];    // Here.
     int Matrix2[10][10];	

     printf("This is matrix multiplication program");

     printf("\nEnter the dimensions of two array ");
     scanf("%d %d %d %d", &Row1, &Col1, &Row2, &Col2); 
     // Here. Removed commas. In case you want them, make sure you give them during input
     // ie say 1,2,3,4 while inputting the numbers
     
     printf("\nDmensions of two arrays are Matrix1");
     printf("\nRow1:%d ,Col1:%d \nMatrix2:Row2: %d, Col2:%d" ,Row1, Col1, Row2, Col2);

     if(Col1 == Row2)
     {
           printf("\nCompatible to multiply");
           printf("\nEnter the value of Matrix 1");
                        
	   // Here. You had not made a function call.
           value(Matrix1, Row1, Col1);
           value(Matrix2, Row2, Col2);                
                
      }
      else
      {
           printf("\n not a compatible type to multiply");

      }

      getchar();	 
      return 0;    
} 


void value(int *Matrix,int a, int b)
{             
     int i = 0, j = 0;

     printf("value of Matrix are\n");
     for(; i < a; i++)
     {
          for(j = 0; j < b; j++)
          {
                  scanf("%d",  (Matrix + i*b +j));
	          printf(" %d", *(Matrix+ i*b +j));				
          }
     }          
     printf("\n");
}

Here is the modified code. i have made many changes, but i have marked the most important ones.

Edited 5 Years Ago by myk45: n/a

thanks yaar..
But i wann my matrix size to be define by user..dont wanna in this predefined way..and i made the function call at same place at u did..
i tried my programm ..their is no syntaz error ..but it just execute till if condition..when i start entering the value of 1 st matrix it got terminated..

>>when i start entering the value of 1 st matrix it got terminated..

Could you paste the modified code here?

well the one i showed in my first post....will work too..
The only modification u have done is u pre defined the matrix size.
THe function call about which u have mentioned in comments..i too have two function calls...

>>The only modification u have done is u pre defined the matrix size.

i changed the scanf() call.

>>THe function call about which u have mentioned in comments..i too have two function calls...

What you had written were not calls. They were prototypes. So, the function was not called.

int func()
{
}

int func1()
{
    func(); // this is a call.
}

int func2()
{
    int func(); // this is not.
}

oh..thats a honest mistake..but dude its still not working.

#include<stdio.h>
#include<conio.h>
void main()

{
void value(int*,int, int);
     printf("This is matrix multiplication program");
     printf("\nEnter the dimensions of two array ");
     int Row1 = 0, Col1 = 0, Row2 = 0, Col2 = 0;
     scanf("%d,%d,%d,%d", &Row1, &Col1, &Row2, &Col2);
     printf("\nDmensions of two arrays are Matrix1:Row1:%d ,Col1:%d \nMatrix2:Row2: %d, Col2:%d" ,Row1, Col1, Row2, Col2);
     if(Col1==Row2)
     {
                  printf("\nCompatible to multiply");
                  int Matrix1[Row1][Col1];
                  int Matrix2[Row2][Col2];
                  printf("\nEnter the value of Matrix 1");
                      
        
     

                   value(Matrix1,Row1, Col1);
                   value(Matrix2,Row2, Col2);                
                
                   }
                   else
                   printf("\n not a compatible type to multiply");
     getch();
     } 


     void value(int *Matrix,int a, int b)
{
         
         {
                    int i=0, j=0;
         for(i=0; i<a; i++)
           {
                 for( j=0; j<b; j++)
                 {
                        scanf("%d",(Matrix+i*b+j));
                        printf("%d",*(Matrix+i*b+j));
                  }
           }
        } 
        }

..

here is the output
This is matrix multiplication program
Enter the dimensions of two array 2, 2, 2, 3

Dmensions of two arrays are Matrix1:Row1:2 ,Col1:2
Matrix2:Row2: 2, Col2:3
Compatible to multiply
Enter the value of Matrix 1 2, 1, 2
2222208876339222935362009340095419936822934844199680

why the second time its not gonna call the function

>> Enter the value of Matrix 1 2, 1, 2

Do not give commas here. i will re-post the code, with outputs.

#include <stdio.h>

void value(int *Matrix,int a, int b);

int main(void)
{     	 
     int Row1 = 0, Col1 = 0, Row2 = 0, Col2 = 0;
  

     printf("This is matrix multiplication program");

     printf("\nEnter the dimensions of two array ");
     scanf("%d,%d,%d,%d", &Row1, &Col1, &Row2, &Col2); 
     // Here. Removed commas. In case you want them, make sure you give them during input
     // ie say 1,2,3,4 while inputting the numbers
     
     printf("\nDmensions of two arrays are Matrix1");
     printf("\nRow1:%d ,Col1:%d \nMatrix2:Row2: %d, Col2:%d" ,Row1, Col1, Row2, Col2);

     if(Col1 == Row2)
     {
		   int Matrix1[10][10];    
		   int Matrix2[10][10];	
           
		   printf("\nCompatible to multiply");
           printf("\nEnter the value of Matrix 1");
                        
	   // Here. You had not made a function call.
           value(Matrix1, Row1, Col1);
           value(Matrix2, Row2, Col2);                
                
      }
      else
      {
           printf("\n not a compatible type to multiply");

      }

      getchar();	 
      return 0;    
} 


void value(int *Matrix,int a, int b)
{             
     int i = 0, j = 0;

     printf("value of Matrix are\n");
     for(; i < a; i++)
     {
          for(j = 0; j < b; j++)
          {
                  scanf("%d",  (Matrix + i*b +j));
	          printf(" %d", *(Matrix+ i*b +j));				
          }
     }          
     printf("\n");
}

Output:

This is matrix multiplication program
Enter the dimensions of two array 2,2,2,2

Dmensions of two arrays are Matrix1
Row1:2 ,Col1:2
Matrix2: Row1:2 ,Col1:2
Compatible to multiply
Enter the value of Matrix 1value of the Matrix are 
2 2 2 2
 2 2 2 2
value of the Matrix are
1 2 3 4
 1 2 3 4

Edited 5 Years Ago by myk45: n/a

This article has been dead for over six months. Start a new discussion instead.