in Education by
So i want to switch the elements of an array with 32 integers "n" times. All elements should be on the next position and the last should be at the first. I tried something like this: while(scanf("%d", &n) != EOF) { for(int j=0; j<n; j++) for(int i=1; i<31; i++) { t[0]=t[31]; tmp=t[i]; t[i]=t[i+1]; } } Im not sure how could I use the tmp variable to solve this problem. this is the array's element: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 and it should look like this if the n=1: 32 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Following is not an edit of your code, but a more efficient solution with the runtime of O(n): void rightshift(char array[LENGTH]) { int i, next = array[0]; for (i = 1; i < LENGTH; i++) { char temp = array[i]; array[i] = next; next = temp; } array[0] = next; }

Related questions

0 votes
    So i want to switch the elements of an array with 32 integers "n" times. All elements should be on the next position and the last ... scanf("%d", &n) != EOF) { for(int j=0; j...
asked May 27, 2022 in Education by JackTerrance
0 votes
    So i want to switch the elements of an array with 32 integers "n" times. All elements should be on the next position and the last ... scanf("%d", &n) != EOF) { for(int j=0; j...
asked May 4, 2022 in Education by JackTerrance
0 votes
    I'm trying to run a simulation that involves a large amount of calculations and values. I've got ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 31, 2022 in Education by JackTerrance
0 votes
    I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 30, 2022 in Education by JackTerrance
0 votes
    I would like to find out safe ways of implementing three dimensional arrays of integers in C++, using ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 29, 2022 in Education by JackTerrance
0 votes
    Which one of the following switching is not transparent? A. Circuit switching B. Packet switching C. Both the options D. None of the above...
asked Jan 8, 2023 in Technology by JackTerrance
0 votes
    In which one of the following switching, there will not be any dedicated connection between two hosts? A. Circuit switching ... switching C. Both the options D. None of the above...
asked Jan 8, 2023 in Technology by JackTerrance
0 votes
    The charging in packet switching is ______________ based? A. Packet B. Time C. Both the options D. None of the above...
asked Jan 8, 2023 in Education by JackTerrance
0 votes
    As the resources are reserved between two communicating end systems in circuit switching, ___________ is achieved. A. ... constant rate C. reliability D. store and forward...
asked Jan 6, 2023 in Technology by JackTerrance
0 votes
    Currently I try to switch from vim to emacs and have some difficulty while editing code. For most of ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 17, 2022 in Education by JackTerrance
0 votes
    I am trying to use a BottomNavigationView with Android Navigation to create a standard tabbed application with three ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 5, 2022 in Education by JackTerrance
0 votes
    We have a number of web-apps running on IIS 6 in a cluster of machines. One of those machines is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 25, 2022 in Education by JackTerrance
0 votes
    We have a number of web-apps running on IIS 6 in a cluster of machines. One of those machines is ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    Can anyone tell me what is Switching in Networking? Select the correct answer from above options...
asked Jan 18, 2022 in Education by JackTerrance
...