Jump to content

inner product of a vector

- - - - -

  • Please log in to reply
1 reply to this topic

#1
aruwin

aruwin

    Learning Programmer

  • Members
  • PipPipPip
  • 42 posts
"Create a program that calculates the inner product of a vector, and the data is input from the keyboard."


I tried to do this but I got an error saying that it expects 'float' because there is 'double'.Perhaps you can help me out?



#include <stdio.h>
double main()
{
int i;
double a,b,c,x,y,z;
double ip = 0.0;
double u[] = {a,b,c};
double v[] = {x,y,z};
printf("enter vector here\n");
scanf("%f,%f,%f,%f,%f,%f",&a,&b,&c,&x,&y,&z);
for (i = 0;i < 3;i++)
{
ip = ip + u[i] * v[i];
}
printf("innerproduct%f\n",ip);
return 0;
}

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
%lf is what you should use with doubles, not %f.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users