This is a C Program to find the cross product of two vectors. The cross product or vector product is a binary operation on two vectors in three-dimensional space. It results in a vector that is perpendicular to both and therefore normal to the plane containing them.

Here is source code of the C Program to Compute Cross Product of Two Vectors. The C program is successfully compiled and run on a Linux system. The program output is also shown below.

`#include <string.h>`

`#include <stdio.h>`

`#include <stdlib.h>`

const int LOW = 0;

const int HIGH = 10;

int main(int argc, char **argv) {

`time_t seconds;`

time(&seconds);

srand((unsigned int) seconds);

int u1, u2, u3, v1, v2, v3;

u1 = rand() % (HIGH - LOW + 1) + LOW;

u2 = rand() % (HIGH - LOW + 1) + LOW;

u3 = rand() % (HIGH - LOW + 1) + LOW;

v1 = rand() % (HIGH - LOW + 1) + LOW;

v2 = rand() % (HIGH - LOW + 1) + LOW;

v3 = rand() % (HIGH - LOW + 1) + LOW;

int uvi, uvj, uvk;

uvi = u2 * v3 - v2 * u3;

uvj = v1 * u3 - u1 * v3;

uvk = u1 * v2 - v1 * u2;

printf("The cross product of the 2 vectors \n u = %di + %dj + %dk and \n v = %di + %dj + %dk\n",

u1, u2, u3, v1, v2, v3);

printf(" u X v: %di + %dj + %dk", uvi, uvj, uvk);

return 0;

`}`

Output:

$ gcc CrossProduct.c $ ./a.out The cross product of the 2 vectors u = 0i + 0j + 7k and v = 4i + 7j + 2k u X v: -49i + 28j + 0k

**Sanfoundry Global Education & Learning Series – 1000 C Programs.**

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

advertisement

advertisement

Here’s the list of Best Books in C Programming, Data Structures and Algorithms.

**Next Steps:**

- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

**Related Posts:**

- Apply for Computer Science Internship
- Buy C Books
- Buy Computer Science Books
- Practice Computer Science MCQs
- Apply for C Internship