Commit 9609658c by viakul

Upload New File

parent 1907fa89
Showing with 58 additions and 0 deletions
#include <stdio.h>
#include <math.h>
int dotProduct(int vector1[3], int vector2[3]);
double vectorMagnitude(int vector[3]);
double cosComapare(int vector1[3], int vector2[3]);
int main()
{
int matrix[4][3]={{1,4,6},
{2,-3,1},
{3,5,0},
{3,1,-3}};
int i;
int m;
double value;
for(i=0;i<4;i++){
m=i+1;
while(m<4){
value = acos(cosComapare(matrix[i], matrix[m]));
printf(" the anlge in radians %lf\n", value);
m++;
}
}
return 0;
}
double vectorMagnitude(int vector[3]){
int sumOfSquares = 0;
int i;
for(i= 0; i<3; i++){
sumOfSquares +=vector[i]*vector[i];
}
double magnitude = sqrt(sumOfSquares);
return magnitude;
}
int dotProduct(int vector1[3], int vector2[3]){
int dot = 0;
int i=0;
for(i = 0; i < 3; i++){
dot +=vector1[i] + vector2[i];
}
return dot;
}
double cosComapare(int vector1[3], int vector2[3]){
int dot = dotProduct(vector1, vector2);
double mag1 = vectorMagnitude(vector1);
double mag2 = vectorMagnitude(vector2);
double cosine = dot/(mag1*mag2);
return cosine;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment