Reputation: 31
I have the following code
#include <iostream>
using namespace std;
int main()
{
double v[3];
double M[3][3];
int i,j;
cout << "Enter in the components of vector v:\n";
for(i=0; i<3; i++)
{
cout << "Component " << i+1 << ": ";
cin >> v[i];
}
cout << "Enter in the elements of matrix M:\n";
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
cin >> M[i][j];
}
}
double Mv[3];
Mv[0] = (M[0][0] * v[0]) + (M[0][1] * v[1]) + (M[0][2] * v[2]);
Mv[1] = (M[1][0] * v[0]) + (M[1][1] * v[1]) + (M[1][2] * v[2]);
Mv[2] = (M[2][0] * v[0]) + (M[2][1] * v[1]) + (M[2][2] * v[2]);
cout << "The product of Mv is: " << Mv[3] << endl;
return 0;
}
When the user enters in the elements of the matrix it simply goes to the next line etc...
How can I make it so that when the user inputs the code, it shows the actual matrix and not just a list of 9 elements.
Upvotes: 1
Views: 10936
Reputation: 544
It depends on the users. Users can enter the elements of 3x3 matrix with spaces and a new line (after 3 elements):
Upvotes: 1