#include "iostream"\n#include "vector"\n\nusing namespace std;\n\nint main() {\n int n;\n cout << "Enter the dimension of the vectors: " ;\n cin >> n;\n\n vector veca(n), vecb(n);\n\n cout << "Enter the elements of vector a: " ;\n for (int i = 0; i < n; i++) {\n cin >> veca[i];\n }\n\n cout << "Enter the elements of vector b: " ;\n for (int i = 0; i < n; i++) {\n cin >> vecb[i];\n }\n\n int dotProduct = 0;\n for (int i = 0; i < n; i++) {\n dotProduct += veca[i] * vecb[i];\n }\n\n cout << "Dot product of the vectors: " << dotProduct << endl;\n\n return 0;\n}


原文地址: https://www.cveoy.top/t/topic/pHQ8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录