Quiz 7

Last quiz everyone!!!!! jajajaja in this quiz I had to calculate the dot product of two vectors “seen in physics”, using arrays.

//CODE:

#include <iostream>
using namespace std;

double dot_product(double list1[], double list2[], int l1){
double dot=0;
for(int i=0; i<l1; i=i+1){
dot=dot+(list1[i]*list2[i]);
}
return dot;
}

int main(){
int l1;
double product;

cout<<“This program help to calculate the dot product of the lists of values given by the user.”<<endl;
cout<<“Please enter the values to the first list.”<<endl;
cout<<“How many caracters the lists have?”<<endl;
cin>>l1;
double list1[l1], list2[l1];

for(int i=0; i<l1; i=i+1){
cout<<“Type the ” <<i+1<<” “<<“value of the 1st list.”<<” “;
cin>>list1[i]; }
cout<<“Please enter the values to the second list.”<<endl;

for(int i=0; i<l1; i=i+1){
cout<<“Type the ” <<i+1<<” “<<“value of the 2nd list”<<” “;
cin>>list2[i]; }

product=dot_product(list1, list2, l1);
cout<<“The dot product of both lists is:”<<” “<<product<<endl;
return 0;
}

Captura de pantalla 2016-04-30 a las 21.57.50.png

CC BY-SA 4.0 Quiz 7 by everolivares is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.