Question: Linear Algebra API ( C programming ) Description: In this part of the assignment, you are to implement functions to initialize or set vectors and
Linear Algebra API ( C programming )
Description: In this part of the assignment, you are to implement functions to initialize or set vectors and functions to manipulate vectors for a Linear Algebra API.
Output: The output must be the same as in the example below. Notice that random numbers may be different on your computer. To make sure that your program produces the correct answer, iLeap uses a seed. Do not add any seed to your program.
Sample Output 1
Welcome to Linear Algebra Begin reverseRotateVectors Before reverseVector 8 11 16 26 15 17 After reverseVector 17 15 26 16 11 8 After rotateOneLeft 15 26 16 11 8 17 After rotateOneRight 17 15 26 16 11 8 After rotateNleft 16 11 8 17 15 26 After rotateNright 17 15 26 16 11 8 End reverseRotateVectors End Linear Algebra
----------------------------------------
CODE must use:
#include#include #include #define VECMAX (6) #define LOW (7) #define HIGH (27) #define NPOS (3) typedef int Item; typedef int Index; typedef Item Vector[VECMAX]; // prototypes for CSC 111 Vector API // functions for testing Vector API int main(void); void printVector(char *msg, Index len, const Vector v); int prngInt(int iLow, int iHigh); float prngFloat(float fLow, float fHigh, float precision); void setRandomVector(Index len, Vector v, Item low, Item high); void reverseRotateVectors(void); // reverse and rotate vectors void reverseVector(Index len, Vector v); void rotateOneLeft(Index len, Vector v); void rotateOneRight(Index len, Vector v); void rotateNleft(Index len, Vector v, Index pos); void rotateNright(Index len, Vector v, Index pos); int main(void) { printf("Welcome to Linear Algebra "); reverseRotateVectors(); printf("End Linear Algebra "); return EXIT_SUCCESS; }//main void reverseRotateVectors(void) { printf("Begin reverseRotateVectors "); Index len = VECMAX; Item v[VECMAX]; setRandomVector(len, v, LOW, HIGH); printVector("Before reverseVector", len, v); reverseVector(len, v); printVector("After reverseVector", len, v); rotateOneLeft(len, v); printVector("After rotateOneLeft", len, v); rotateOneRight(len, v); printVector("After rotateOneRight", len, v); rotateNleft(len, v, NPOS); printVector("After rotateNleft", len, v); rotateNright(len, v, NPOS); printVector("After rotateNright", len, v); printf("End reverseRotateVectors "); }//reverseRotateVectors void printVector(char *msg, Index len, const Vector v) { // print all values of 'v' onto one console line printf("%s ", msg); for (Index k = 0; k < len; k++) printf("%d ", v[k]); printf(" "); }//printVector int prngInt(int iLow, int iHigh) { int mod = iHigh - iLow + 1; return rand() % mod + iLow; }//prngInt float prngFloat(float fLow, float fHigh, float precision) { int iLow = (int) (fLow * precision); int iHigh = (int) (fHigh * precision); int mod = iHigh - iLow + 1; int irn = rand() % mod + iLow; return ((float) (irn)) / precision; }//prngFloat void setRandomVector(Index len, Vector v, Item low, Item high) { // initialize each component of 'v' with a pseudo // random numbers in the range of 'low' to 'high' for (Index k = 0; k < len; k++) v[k] = prngInt(low, high); }//setRandomVector void reverseVector(Index len, Vector v) { // reverse the elements in the array // Ex: [1 7 6 2 4] ==> [4 2 6 7 1] // replace with your code for reverseVector }//reverseVector void rotateOneLeft(Index len, Vector v) { // rotate all array elements one position // to the left without losing any elements // move the first element into the last // Ex: [1 7 6 2 4] ==> [7 6 2 4 1] // replace with your code for rotateOneLeft }//rotateOneLeft void rotateNleft(Index len, Vector v, Index pos) { // rotate all array elements N positions // to the left without losing any elements // the elements that fall of the front // are moved to the end of the array // replace with your code for rotateNleft }//rotateNleft void rotateOneRight(Index len, Vector v) { // rotate all array elements one position // to the right without losing any elements // move the first element into the last // Ex: [1 7 6 2 4] ==> [7 6 2 4 1] // replace with your code for rotateOneRight }//rotateOneRight void rotateNright(Index len, Vector v, Index pos) { // rotate all array elements N positions // to the right without losing any elements // the elements that fall of the front // are moved to the end of the array // replace with your code for rotateNright }//rotateNright
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
