title: Matrix Vector Multiplication in C++
body: <p>I've a code to multiply matrix and a vector. But, it doesn't <strong>enter inside the</strong> <code>for</code> loop in the friend function <code>calc()</code>. Can you spot the error?</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  class vector;
  class matrix
  {
  public:
      int r,c,ma[10][10];
      void get(int r, int c=3)
      {
          int i,j;
          cout&lt;&lt;"Enter the matrix elements\n";
          for(i=0; i&lt;r; i++)
              for(j=0; j&lt;c; j++)
              {
                  cin&gt;&gt;ma[i][j];
              }
          cout&lt;&lt;"Your input: ";
          for(i=0; i&lt;r; i++)
          {
              cout&lt;&lt;"\n";
              for(j=0; j&lt;c; j++)
              {
                  cout&lt;&lt;ma[i][j]&lt;&lt;"\t";
              }
          }
      }
      friend void calc(matrix m,vector v);
  };
  
  class vector
  {
  public:
      int val,va[10];
      void get(int v=3)
      {
          int i;
          cout&lt;&lt;"\nEnter the vector values\n";
          for(i=0; i&lt;v; i++)
          {
              cin&gt;&gt;va[i];
          }
          cout&lt;&lt;"\nYour input:\n";
          for(i=0; i&lt;v; i++)
          {
              cout&lt;&lt;va[i]&lt;&lt;"\t";
          }
      }
      friend void calc(matrix m,vector v);
  };
  
  void calc(matrix m,vector v)
  {
      int c[10],i,j;
      if(m.c == v.val)
      {
          for(i=0; i&lt;v.val; i++)
          {
              cout&lt;&lt;"Entered 1st loop";
              c[i] = 0;
              for(j=0; j&lt;m.r; j++)
              {
                  c[i] = c[i]+(m.ma[i][j] * v.va[j]);
              }
          }
      }
      cout&lt;&lt;"\nThe result is :\n";
      for(i=0; i&lt;m.r; i++)
      {
          cout&lt;&lt;"Entered for";
          cout&lt;&lt;"\n"&lt;&lt;c[i];
      }
  }
  
  int main()
  {
      int r;
      matrix m1;
      vector v1;
      cout&lt;&lt;"Enter the number of rows = ";
      cin&gt;&gt;r;
      m1.get(r);
      v1.get();
      calc(m1,v1);
      return 0;
  }
  </code></pre>