161/2S3, Homework Problem Set 4. Due Date: Friday May 3rd, 2002

advertisement
161/2S3, Homework Problem Set 4.
Due Date: Friday May 3rd, 2002
Write two versions of the same program to add two vectors, A and B. The vectors should
be declared as structures in the following way
typedef struct{ double n;
double entry[3];
} vector;
and the addition should be carried out in a function. The program should prompt the
user to input the three components, entry[0], entry[1] and entry[2], from which the
length, n of the vector can be determined. The result of the addition, a third vector C,
should be printed out for the user.
1. The first version should use “call by value” and return a value of type vector from
the function. Submit this to directory
161:6 with the source called: “p06.c”
2. The second version should use “call by reference” ie use pointers. Note that there
should be no return statement in the function for this program. Submit this to
directory
161:7 with the source called: “p07.c”
Download