0

My code is giving a wrong output for the 3rd pair of vectors im finding the dot product of, although the first two are correct. (outputs - 0, 3, -3(should be 1))... I just cant find wahts wrong, i was guessing something to do with the -1 in the b array but no clues.
any help please and thankyou?

#include <stdio.h>
#include <math.h>

void vector_info(float[], float[]);
double dot(float[], float[]);

int main ()
{
float a[3]={1,1,0};
float b[3]={-1,1,0};
float c[3]={1,2,3};
vector_info(a ,b);
vector_info(a ,c);
vector_info(c ,b);
system("pause");
return 0;
}

void vector_info(float a[], float b[])
{
printf(" a . b = %4.1f\n", dot);
}

double dot(float a[], float b[])
{
return ((a[0]*b[0]) + (a[1]*b[1]) + (a[2]*b[2]));
}

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by becka221
Featured Replies
  • 1

    [CODE]printf(" a . b = %4.1f\n", dot(a, b));[/CODE] Did you miss this out? i checked the output. i got 1.0 for c.b. That is correct right? Read More

1
printf(" a . b = %4.1f\n", dot(a, b));

Did you miss this out? i checked the output. i got 1.0 for c.b. That is correct right?

0

God. I can't beleive I missed out something so simple.
Cheers its been bugging me for ages.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.