C Write a program which multiplies two matrices The matrices
C++
Write a program which multiplies two matrices. The matrices may be any size, contain integers, and will come as input from the user. Each matrix will be input with the columns separated by spaces and the rows each on a new line. The end of each matrix will be specified by an empty line with no integers. Your program should print the resulting matrix with each column separated by a space, and each row on a new line.
Remember that the matrix product is defined as:
(AB)ij = sum of (Aik * Bkj) for k = 1 to m (where m is the number of columns in A)
Your program should output an error if the dimensions of the input matrices are incompatible (the number of columns in the first is not equal to the number of rows in the second).
Each input matrix should be stored in a multidimensional integer array. You may also want to use a multidimensional array to store the result matrix. All three matrices have sizes less or equal 10 by 10.
The input and output are given as exactly as below. You cannot ask the user for the number of columns and rows. Instead the program has to somehow count the number of rows and columns using loops. Also if you take a look at the input for the first and second matrices, each has two blank lines below each one which is to signify the end of each matrix.
Same problem/code as: http://www.chegg.com/homework-help/questions-and-answers/write-program-multiplies-two-matrices-matrices-may-size-contain-integers-come-input-user-m-q7579111
  but using C++ please
Solution
#include <iostream>
 #include <stdio.h>
 #include <sstream>
 #include <string>
 using namespace std;
int main()
 {
     int a[10][10], b[10][10],c[10][10];
     int x=0,y=0,i=0,j=0,m=0,n=0;
     string temp;
     cout<<\"Enter first matrix\ \";  
     while(getline(cin,temp))
     {
         if(temp==\"\")
             break;
         int te;
         j=0;
         istringstream iss(temp);
         while(iss>>te)
         {
             a[i][j]=te;
             j++;
         }
         y=j;
         i++;
     }
     x=i;
     i=0;
     cout<<\"Enter second matrix\ \";
     while(getline(cin,temp))
     {
         if(temp==\"\")
             break;
         int te;
         j=0;
         istringstream iss(temp);
         while(iss>>te)
         {
             b[i][j]=te;
             j++;
         }
         n=j;
         i++;
     }
     m=i;
     if(y==m)
     {
 
         for(i=0;i<x;i++)
         {
             for(j=0;j<n;j++)
             {
                 c[i][j]=0;
                 for(int k=0;k<m;k++)
                 {
                     c[i][j]=c[i][j]+a[i][k]*b[k][j];
                 }
             }
         }
 
         cout<<\"The product is\ \";
 
         for(i=0;i<x;i++)
         {
             for(j=0;j<n;j++)
             {
                 cout<<\"\\t\"<<c[i][j];
             }
             cout<<\"\ \";
         }
     }
     else
     {
         cout<<\"The two matrices have incompatible dimensions\ \";
     }
     return 0;
 }