Created
April 20, 2016 17:29
-
-
Save batmantec/97d706c8360ca81cd56740dfab00d067 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> | |
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