Check your program carefully before submission Test data dif

Check your program carefully before submission. Test data differs from the sample input will be used in the grading. Make sure your program work properly for all possible cases. You just need to fill the content of hw2.c, do not change the form of the function. It is fine that the main function remains blank. Functions Finish the following functions in hw2.c. void vector_input(float v[], int n): input the elements of vector v and store in the array. void vector. output (float v[], int n): output the elements of vector v on the screen. void vector_add(float v1 [], float v2[], float v3[], int n): calculate the sum of vector v1 and v2 and store the result in r3. The sum is a vector, not a single value. void vector.multiplv(float v[].int n.float x): multiply each element in v by x float inner .product (float vl(J, float v2[), int n): return the inner product of vector v1 and r2. float length(float v[], int n): return the length of vector v Sample Input and Output vector_add: (1.2, 3.5, 5.7)+(3.2, 1, 6.3)=(4.4, 4.5, 12) vector_multiply: (2.2, 4.1, 6.5)x3=(6.6, 12.3, 19.5) inner_product: (1, 2, 3)(4, 5, 6)=lx4+2x5+3x6=4+10+18=32 length: length of vector (3.4, 5) is Squareroot 9 + 16 + 25 = Squareroot50 = 7.071068

Solution

void vector_input(float v[],int n)
{
printf(\"Enter %d values \",n);
for ( int j=0;j< n;j++){
printf(\"enter the integer number %d\ \", x);
scanf(\"%f\", &v[j]);
}
}
----------------------------------------------------------
void vector_output(float v[],int n){
printf(\"Values in vector are: \ \");
for (int j=0; j<n; j++)
{
printf(\"%d ,\", v[j] );
}
----------------------------------------------------------------------
void vector_add(float v1[],flaotv2[],float v3[],int n){
int j;
float v3[];
for( j =0;j<n;j++)
{
v3[j]= v1[j] + v2[j];
}
System.out.println(\"vector_add: \");
for ( j=0; j<n; j++)
{
printf(\"%d ,\", v3[j]);
}
}
-------------------------------------------------------------------
void vector_multiply(float v1[],float x,int n){
int j;
for( j =0;j<n;j++)
{
v1[j]= x * v2[j];
}
System.out.println(\"vector_multiply: \");
for ( j=0; j<n; j++)
{
printf(\"%d ,\", v1[j]);
}
}
----------------------------------------------------------------------
float inner_product(float v1[],float v2[],int n){
int j;
float inner_prd=0;
float v3[n];
for(j=0;j<n;j++){
v3[j]=v1[j]*v2[j];
}
for(j=0;j<n;j++){
inner_prd=inner_prd+v3[j];
}
System.out.println(\"Inner_product is %f:\",inner_prd);
}
-------------------------------------------------------------------------
float length(float v[],int n){
int j;
float len=0;
for(j=0;j<n;j++){
len=len+(v[j]*v[j]);
}
printf(\"Length: %lf \",sqrt(len));
}

 Check your program carefully before submission. Test data differs from the sample input will be used in the grading. Make sure your program work properly for a
 Check your program carefully before submission. Test data differs from the sample input will be used in the grading. Make sure your program work properly for a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site