Question 1. Write a program that uses the structure type declared below to store and operate on integer vectors.
struct vector {
int *values;
int length;
};
Your program should perform the following tasks: 1) read two vectors from standard input with each vector entered in the format N, v1, v2, ..., vN, where N is the vector length (number of elements), each vi is the ith vector element, and successive integers in the vector specification are separated by commas and zero or more white space characters; 2) store the vectors that are read using dynamic memory allocation so that the amount of memory allocated is streamlined based on the given vector lengths; 3) report an error message and exit if there is not adequate free memory to satisfy the memory allocation request or if the two vectors that are read have different vector lengths. If Step 3 does not result in an error being detected, then 4) compute the inner product of the two vectors, and print the result to the screen; and 5) determine and print the value of the vector element (or elements, in case of a tie) that has minimum absolute value among all of the elements in both vectors. Use the scanf and printf functions for all input and output.
|