Skip to content

Instantly share code, notes, and snippets.

@batmantec
Created April 20, 2016 17:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save batmantec/97d706c8360ca81cd56740dfab00d067 to your computer and use it in GitHub Desktop.
Save batmantec/97d706c8360ca81cd56740dfab00d067 to your computer and use it in GitHub Desktop.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int dotProduct(int num1, int num2){
int ans;
ans = num1*num2;
return ans;
}
int main (){
int i, x, save = 0, sum;
cout << "This program calculates the dot product." << endl;
cout << "Type the number of values for each array you will be using: ";
cin >> i;
cout << endl;
int list1[i], list2[i];
for (x = 0; x < i; x++) {
cout << "Type the value " << x << " for the first array: ";
cin >> list1[x];
}
cout << endl;
for (x = 0; x < i; x++) {
cout << "Type the value " << x << " for the second array: ";
cin >> list2[x];
}
for (x = 0; x < i; x++) {
sum = dotProduct(list1[x], list2[x]);
save += sum;
}
cout << "The dot product is :" << save;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment