Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Time limit: 5000ms Memory limit: 256mb Description: Given an integer array A and an integer number k, please perform a circular right shift on the

Time limit: 5000ms Memory limit: 256mb Description: Given an integer array A and an integer number k, please perform a circular right shift on the array by k steps. -----------------------Copy the following code, complete it and submit----------------------- /* I, , am submitting the assignment for an individual project. I declare that the assignment here submitted is original except for source material explicitly acknowledged, the piece of work, or a part of the piece of work has not been submitted for more than one purpose (i.e. to satisfy the requirements in two different courses) without declaration. I also acknowledge that I am aware of University policy and regulations on honesty in academic work, and of the disciplinary guidelines and procedures applicable to breaches of such policy and regulations, as contained in the University website http://www.cuhk.edu.hk/policy/academichonesty/. It is also understood that assignments without a properly signed declaration by the student concerned will be graded as zero by the teacher(s). */ #include  int circular_right_shift(int a[], int output[], int n, int k) { // WRITE YOUR CODE HERE } // DO NOT MODIFY THE CODE BELOW int print_output(int output[], int n) { int i = 0; for (i = 0; i < n; i++) { printf("%d ", output[i]); } printf(" "); return 0; } int main() { int a[10240]; int output[10240]; int n, k, i; // read the input array and k scanf("%d", &n); scanf("%d", &k); for (i = 0; i < n; i++) { scanf("%d", &a[i]); } // initialize the array output for (i = 0; i < n; i++) { output[i] = 0; } int res = circular_right_shift(a, output, n, k); print_output(output, n); return 0; } -----------------------------------------End of Code----------------------------------------- Input: The first line contains two integers: N and k (k can be 0); The second line contains a, an array of N integers, a_0, a_1, ..., a_(N-1); 0 <= N <= 10^3 Output: The shifted array. Sample Input 1: 4 3 1 2 3 4 The first shift: 4 1 2 3 The second shift: 3 4 1 2 The third shift: 2 3 4 1 Therefore, Sample Output 1: 2 3 4 1 Sample Input 2: 1 5 100 Sample Output 2: 100 Sample Input 3: 3 0 3 2 1 Sample Output 3: 3 2 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Sams Teach Yourself Beginning Databases In 24 Hours

Authors: Ryan Stephens, Ron Plew

1st Edition

067232492X, 978-0672324925

More Books

Students also viewed these Databases questions