I tried to make a program to calculate the dot product or inner product of 2 vectors but the results won't turn out right.
Tell me what is wrong.
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int i;
double ip = 0.0;
double u[1];
double v[1];
for (i=0; i<3; i++) {
ip = ip + u[i]*v[i];
return ip;
const int size = 1;
double v1[size], v2[size];
printf("Enter the components of%f\n");
printf("the first vector: %f\n");
for(int j=0; j<size; j++);
printf("the second vector: %f\n");
for(int j=0; j<size; j++);
double dot = (v1, v2, size);
printf("dot product of the vectors:%f\n",ip);
return 0;
}}
3 replies to this topic
#1
Posted 07 November 2011 - 05:35 AM
|
|
|
#2
Posted 07 November 2011 - 09:44 AM
You have a return statement before you enter the vector. Why?
#3
Posted 07 November 2011 - 09:53 AM
WingedPanther said:
You have a return statement before you enter the vector. Why?
I have erased the return statement but it still didn't work.Why?
#4
Posted 07 November 2011 - 10:03 AM
Immediate issues I see:
1) You don't have a scanf anywhere, which means you never get input from the user.
2) Your arrays only hold 1 element, which will stop you from storing the full input from the user.
3) Your loop to calculate the inner product performs calculations prior to getting input.
1) You don't have a scanf anywhere, which means you never get input from the user.
2) Your arrays only hold 1 element, which will stop you from storing the full input from the user.
3) Your loop to calculate the inner product performs calculations prior to getting input.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









