-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvector_mult.c
More file actions
41 lines (31 loc) · 1.01 KB
/
vector_mult.c
File metadata and controls
41 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define VECTOR_SIZE 3
void initalize_vectors(int vector[VECTOR_SIZE]) {
for(size_t i = 0; i < VECTOR_SIZE; i++) {
printf("%lu :", i);
scanf("%d", &vector[i]);
}
}
void vector_crossProduct(int vec_A[VECTOR_SIZE], int vec_B[VECTOR_SIZE], int vec_C[VECTOR_SIZE]) {
vec_C[0] = (vec_A[1] * vec_B[2]) - (vec_A[2] * vec_B[1]);
vec_C[1] = (vec_A[0] * vec_B[2]) - (vec_A[2] * vec_B[0]);
vec_C[2] = (vec_A[0] * vec_B[1]) - (vec_A[1] * vec_B[0]);
}
char* sign(int a) {
return (a < 0) ? "-" : "+";
}
int main(int argc, char const *argv[]) {
int vec_A[VECTOR_SIZE];
int vec_B[VECTOR_SIZE];
int vec_C[VECTOR_SIZE];
printf("Initialize A:\n");
initalize_vectors(vec_A);
printf("Initialize B:\n");
initalize_vectors(vec_B);
vector_crossProduct(vec_A, vec_B, vec_C);
printf("Cross product:\nC : %s%di %s %dj %s %dk\n",
sign(vec_C[0]), abs(vec_C[0]), sign(vec_C[1]), abs(vec_C[1]), sign(vec_C[2]), abs(vec_C[2]));
return 0;
}