I'm not getting the desired output. I want to rotate the array towards left by one index. Please help. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I'm not getting the desired output. I want to rotate the array towards left by one index. Please help.

#include <stdio.h> #include <stdlib.h> #include <stddef.h> void arrayRotate (int array[],int n) {    int temp = 0;    int index = 0;    temp = array[n-1];    array[n-1] = array[0];    for (index=1; index<=n-1; index++){        array[index-1] = array[index];    }     array[n-2] = temp;    return 0; } int main() {    int values[] = {5,6,7,8};    int length = sizeof(values)/sizeof(values[0]);    arrayRotate(values,length);    for (int i=0;i<length;i++)    printf("the rotated array is %d",values[i]);    return 0; }

29th Jun 2020, 8:58 AM
Ankush Raj
Ankush Raj - avatar
1 Answer
+ 1
Here's something I did a while back...there's a rotate left (and right) in it along with some other array related stuff. https://code.sololearn.com/cAZQ1OfIR02A/#c
29th Jun 2020, 9:30 AM
rodwynnejones
rodwynnejones - avatar