Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that reads in two integer vectors, computes the dot product of t

ID: 3576186 • Letter: W

Question

Write a program that reads in two integer vectors, computes the dot product of the vectors, and displays the results. The dot product of two vectors is calculated by summing the product of corresponding terms. For example: [1 3 5]. [2 4 6] 1*2 + 3*4 + 5*6 44 Store each vector in an array. (Allow for up to 100 elements per vector.) After displaying the dot product, ask the user if they want to compute another dot product. Here is a sample run: CIS133u Program 8 Track 1 - Computing the dot product using a function. Enter the number of terms: 3 Enter the first vector: 1 3 5 Enter the second vector: 2 4 6 The dot product is 44 Compute another dot product? (y/n) y Enter the number of terms: 4 Enter the first vector: 2 4 6 8 Enter the second vector: 1 0 0 1 The dot product is 10 Compute another dot product? (y/n) n Computer: Good-bye! where Vec1 and Vec2 are two vectors. numTerms is the number of active terms in each vector. Arrays Vec1 and Vec2, and the value numTerms are input to function dotProduct, which only does the calculations and returns the calculated value via its return statement.

Explanation / Answer

*********************Program.c**********************

#include <stdio.h>


int main()
{
int i,v1[100],v2[100];
    int n=0;
    char choice;


   do{
       printf("Enter the number of terms: ");
   scanf("%d",&n);

        printf(" Enter first vector : ");
   for(i=0;i<n;i++)
   {
        scanf("%d",&v1[i]);
        }

printf(" Enter second vector : ");
for(i=0;i<n;i++)
{
scanf("%d",&v2[i]);
}
       dotProduct(v1,v2,n);
       printf(" Compute another Dot Product(y/n):");
       scanf(" %c",&choice);
       printf(" ",choice);
   }while(choice=='y');
       printf(" Computer:Good-Bye!");
   return 0;
  

}
  
int dotProduct(int vec1[],int vec2[],int numTerms){
    int sum=0;
    int i;
    for(i=0;i<numTerms;i++)
{
   sum= sum + vec1[i]*vec2[i];
}
printf(" The dot product is: %d",sum);
}

****************************OUTPUT***************************

Enter the number of terms: 3

Enter first vector : 1
3
5

Enter second vector : 2
4
6

The dot product is: 44
Compute another Dot Product(y/n):y

Enter the number of terms: 4

Enter first vector : 2
4
6
8

Enter second vector : 1
0
0
1

The dot product is: 10
Compute another Dot Product(y/n):n


Computer:Good-Bye!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote