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

Problem 1: Cross product and dot product of two vectors V 1 and V 2 are V_1 (cro

ID: 2987990 • Letter: P

Question

Problem 1: Cross product and dot product of two vectors V1 and V2 are

V_1 (cross) V_2 = (Vy1*Vz2 - Vy2*Vz1) i + (Vz1*Vx2 - Vz2*Vx1) j + (Vx1*Vy2 - Vx2*Vy1) k

V_1 (dot) V_2= Vx1*Vx2 + Vy1*Vy2 + Vz1*Vz2

a) User will be asked to supply the vector coefficients and save those into two arrays.

b) Write two functions to compute cross product and dot products of any two vectors.

   i) Vectors must be passed as arrays to these functions (input arguments).

ii) These functions will print the computed values only and will not return any value to the calling function (main).

Test your program using the following vectors:

R1 = 5i + 2j - 4k and R2 = i + 3k

i) R1 (cross) R2    ii) R1 (dot) R2    iii) R1 (cross) R1 and iv) R1 (dot) R1

Explanation / Answer

#include <stdio.h>
#include <stdlib.h>

void dot_product(int vec1[3], int vec2[3])
{
   int result = vec1[0]*vec2[0]+vec1[1]*vec2[1]+vec1[2]*vec2[2];
   printf("The dot_product is : %d ", result);
}

void cross_product(int vec1[3], int vec2[3])
{
   int result_i = vec1[1]*vec2[2]-vec1[2]*vec2[1];
   int result_j = vec1[2]*vec2[0]-vec1[0]*vec2[2];
   int result_k = vec1[0]*vec2[1]-vec1[1]*vec2[0];
   printf("The cross_product is : %di+%dj+%dk ", result_i, result_j, result_k);
}

int main()
{
   int vec1[3];
   int vec2[3];
  
   printf("Enter the co-efficients of first vector ");  
   printf("i:");
   scanf("%d", &vec1[0]);
   printf("j:");
   scanf("%d", &vec1[1]);
   printf("k:");
   scanf("%d", &vec1[2]);

   printf("Enter the co-efficients of second vector ");  
   printf("i:");
   scanf("%d", &vec2[0]);
   printf("j:");
   scanf("%d", &vec2[1]);
   printf("k:");
   scanf("%d", &vec2[2]);

   dot_product(vec1, vec2);
   cross_product(vec1, vec2);
}