Question: Complete the program below so that it rotates the array, x, of doubles by the integer rotation amount, ROTATION. The method creates a new array

Complete the program below so that it rotates the array, x, of doubles by the integer rotation amount, ROTATION. The method creates a new array with the items of x moved forward by n positions. Elements that are rotated off the array will appear at the end. For example, suppose x contains the following items in sequence: 1 2 3 4 5 6 7 After rotating by 3, the elements in the new array will appear in this sequence: 4 5 6 7 1 2 3 Array x should be left unchanged by this method; array y should contain the rotated values. Be sure to test your program with different rotation amounts.

#include /* * outputArray : double[], int, char * * function is given an array of doubles, its size, * and its (char) name * function then outputs the array */ void outputArray(double array[], int size, char name) { int i; for (i = 0; i < size; i++) { printf("%c[%d]: %0.1f ", name, i, array[i]); } } /* * program rotates an array of doubles */ int main() { const int ROTATION = 3; // the # of array elements to rotate const int ARRAY_SIZE = 9; // the size of the rotated array double x[] = {8, 4, 5, 21, 7, 9, 18, 2, 100}; // original array double y[ARRAY_SIZE]; // rotated array // temp variables here printf(" Before rotation: ============================== "); // output original array outputArray(x, ARRAY_SIZE, 'x'); // ROTATION CODE STARTS HERE // ROTATION CODE ENDS HERE printf(" After rotation: ============================== "); // output rotated array outputArray(y, ARRAY_SIZE, 'y'); // end program return 0; }

Once you are done, write your code to copy

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!