0

how do i make a program that calculates the product of two vectors in C ?

this is what i have but i think im doing it wrong i need some help?

#include <stdio.h>
double inner(double m[ ] , double n[ ] , int size ) ;
int main( int argc, char *argv[ ] ) {

int i,k ;

double m[8] , n[8] ;

for(i = 0 ; i < 8 ; i++ ) {

printf("Please enter a number for m :") ;
scanf("%lf",&m[i]) ;
}
for(k=0 ; k < 8 ; k++ ) {

printf("{{lease enter a number for n :") ;
scanf("%lf",&n[i]) ;
}

printf("The inner product of the two vectors is : %lf ",inner(m,n,8 ) ) ;


return 0 ;

}


double inner(double m[ ] , double n[ ] , int size ){

int j ;
double sum = 0.0 ;

for( j = 0 ; j < size-1 ; j++){

sum =+ (m[j] * n[j]) ;

}

return sum ;

}

Edited by rockerjhr: n/a

2
Contributors
3
Replies
6
Views
6 Years
Discussion Span
Last Post by Dervish1
0

Your inner() function doesn't multiply the last set of values. On line 33, the loop termination should be j < size.

That's the only issue that comes to mind; assuming your inner product algorithm is correct.

0

i meant calculating the inner product of two vectors , I dont think my inner function is correct thats why I need help with it :(

0

Ah ... well, that one's a math question. From a quick scan of Wikipedia, I believe your algorithm is right (except for the fencepost error at the end). You might want to check that part on a math forum...

This topic has been dead for over six months. 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.