i copied the code as is discussed by my professor and written in my course book but i am not getting the correct output. my logic is very clear but not getting the right output, its a bunch of positive n negative values. pls check . the code is compiling well .

#include<iostream.h>
#include<conio.h>
    int main()
     {   int m,n,r;
        cout<<"enter the order ";
        cin>>m>>n>>r;
         int mat1[10][10] ,mat2[10][10],mat3[20][20];
        cout<<"enter the elements of first array " <<endl;
       for(int i=0;i<m;i++)
       {
               for(int j=0;j<n;j++)
               {
                       cin>>mat1[i][j];
               }
       }
       cout<<"enter the elements of the sec matrix ";
     for(int i=0;i<n;i++)
       {
               for(int j=0;j<r;j++)
               {
                       cin>>mat2[i][j];
               }
       }
       cout<<"\n the resultant matrix is "<<endl;
       for( int i=0;i<m;i++)
       {
          for( int j=0;j<n;j++)
          {
              mat3[i][j]=0;
              for( int k=0;k<r;k++)
              {
                      mat3[i][j]=mat3[i][j]+(mat1[i][k]*mat2[k][j]);
                      cout<<mat3[i][j]<<" ";         
                      
              }
              
          cout<<mat3[i][j]<<" ";    
          } 
          cout<<endl;
          
       }   
     
        getch();
        return 0;
    }

Recommended Answers

All 2 Replies

Member Avatar for iamthwee

#include<iostream.h>

should be

#include <iostream>

using namespace std;

and the getch();

should be cin.get();

It shud work now!

:cool:

See The Changes

#include<iostream.h>
#include<conio.h>
    int main()
     {   
		int m,n,r;
        cout<<"enter the order ";
        cin>>m>>n>>r;
         int mat1[10][10] ,mat2[10][10],mat3[20][20];
        cout<<"enter the elements of first array " <<endl;
       for(int i=0;i<m;i++)
       {
               for(int j=0;j<n;j++)
               {
                       cin>>mat1[i][j];
               }
       }
       cout<<"enter the elements of the sec matrix ";
     for(i=0;i<n;i++)
       {
               for(int j=0;j<r;j++)
               {
                       cin>>mat2[i][j];
               }
       }
       cout<<"\n the resultant matrix is "<<endl;
       for(i=0;i<m;i++)
       {
          for( int j=0;j<r;j++)
          {
              mat3[i][j]=0;
              for( int k=0;k<n;k++)
              {
                      mat3[i][j]=mat3[i][j]+mat1[i][k]*mat2[k][j];
                  }
              } 
          }   
     for(i=0;i<m;i++)
       {
          cout<<endl;     
		  for(int j=0;j<r;j++)
               {
                       cout<<mat3[i][j]<<"  ";
               }
       }
        getch();
        return 0;
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.