1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
#include <iostream>
using namespace std;
bool vect(int n, int m)
{
if(n==m)
return 1;
else
return 0;
}
void printvect (int *vec1, int *vec2,int*a,int *b, int *c)
{
cout<<"The values for Vector 1 are (";
for(int i=0;i<*a-1;i++)
{
cout<<vec1[i]<<" , ";
}
cout<<vec1[*a-1]<<")"<<endl<<endl;
cout<<"\nThe values for Vector 2 are (";
for(int i=0;i<*b-1;i++)
{
cout<<vec2[i]<<" , ";
}
cout<<vec2[*b-1]<<")"<<endl<<endl;
cout<<"The inner product of your Vectors is (";
double vectotal=0;
for(int i=0;i<*c;i++)
{
vectotal=(vec1[i]*vec2[i])+vectotal;
}
cout<<vectotal<<")"<<endl;;
}
int main()
{
int n;
int m;
cout<<"What are the dimensions for Vector 1?"<<endl;
cin>>n;
cout<<"What are the dimensions for Vector 2?"<<endl;
cin>>m;
if
(!vect(n,m))
{cout<<"The dimensions of your vector do not match."<<endl;
return 0;}
else if (vect(n,m))
{
int vec1[n];
int vec2[m];
int k = (m+n)/2;
cout<<"Enter the values for Vector 1."<<endl;
for(int i=0;i<=n-1;i++)
{cin>>vec1[i];
}
cout<<"Enter the values for Vector 2."<<endl;
for(int j=0;j<=m-1;j++)
{
cin>>vec2[j];
}
printvect(vec1,vec2,&n,&m, &k);
return 0;
}
return 0;
}
|