Program for dot product and cross product of two vectors | C ++ implementation for dot product and cross product of two vector . ; Function that return dot product of two vector array . ; Loop for calculate cot product ; Function to find cross product of two vector array . ; Driver function ; dotProduct function call ; crossProduct function call ; Loop that print cross product of two vector array .
#include <bits/stdc++.h> NEW_LINE #define n  3 NEW_LINE using namespace std ; int dotProduct ( int vect_A [ ] , int vect_B [ ] ) { int product = 0 ; for ( int i = 0 ; i < n ; i ++ ) product = product + vect_A [ i ] * vect_B [ i ] ; return product ; } void crossProduct ( int vect_A [ ] , int vect_B [ ] , int cross_P [ ] ) { cross_P [ 0 ] = vect_A [ 1 ] * vect_B [ 2 ] - vect_A [ 2 ] * vect_B [ 1 ] ; cross_P [ 1 ] = vect_A [ 2 ] * vect_B [ 0 ] - vect_A [ 0 ] * vect_B [ 2 ] ; cross_P [ 2 ] = vect_A [ 0 ] * vect_B [ 1 ] - vect_A [ 1 ] * vect_B [ 0 ] ; } int main ( ) { int vect_A [ ] = { 3 , -5 , 4 } ; int vect_B [ ] = { 2 , 6 , 5 } ; int cross_P [ n ] ; cout << " Dot ▁ product : " ; cout << dotProduct ( vect_A , vect_B ) << endl ; cout << " Cross ▁ product : " ; crossProduct ( vect_A , vect_B , cross_P ) ; for ( int i = 0 ; i < n ; i ++ ) cout << cross_P [ i ] << " ▁ " ; return 0 ; }