Created
April 24, 2015 05:50
-
-
Save samir96/c46e38e598c68f2815b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
int dotProduct(vector<int>v1, vector<int>v2){ | |
int multi=0; | |
for (int n=0; n<v1.size(); n++) | |
{ | |
multi=v1[n]*v2[n]+multi; | |
} | |
return multi; | |
} | |
int main(){ | |
vector<int>v1; | |
vector<int>v2; | |
int tam; | |
int num; | |
int tam2; | |
int num2; | |
cout<<"Dame la cantidad de valores de la primer lista:(ambas listas deben tener el mismo tamano)"<<endl; | |
cin>>tam; | |
for(int n=0;n<tam;n++){ | |
cout<<"Dame un numero"<<endl; | |
cin>>num; | |
v1.push_back(num); | |
} | |
cout<<"Dame la cantidad de valores de la segunda lista:(ambas listas deben tener el mismo tamano) "<<endl; | |
cin>>tam2; | |
for(int n=0;n<tam;n++){ | |
cout<<"Dame un numero"<<endl; | |
cin>>num2; | |
v2.push_back(num); | |
} | |
if (tam != tam2) | |
{ | |
cout << "Error: Las listas no son del mismo tamano" << endl; | |
cout << "-1" << endl; | |
} | |
else | |
{ | |
cout<<"El resultado de la multiplicacion es de: "<<dotProduct(v1,v2)<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment