#include <stdio.h>
int rotRight(int arr[],int n,int d){
int no_of_rots = d%n;
int temp[no_of_rots];
int c =0;
for(int i = n- no_of_rots;i<n;i++){
temp[c] = arr[i];
c++;
}
for(int i=n-no_of_rots;i>=0;i--){
arr[i+no_of_rots] = arr[i];}
for(int i = 0;i<no_of_rots;i++){
arr[i] = temp[i];}
return 0;
}
int rotLeft(int arr[],int n,int d){
int no_of_rots = d%n;
int temp[no_of_rots];
for(int i = 0;i<no_of_rots;i++){
temp[i] = arr[i];
}
for(int i = no_of_rots;i<n;i++){
arr[i-no_of_rots] = arr[i];
}
int c = 0;
for(int i = n-no_of_rots;i<n;i++){
arr[i] = temp[c];
c++;
}
return 0;
}
int main()
{
int n,d;
char k;
scanf("%d",&n);
int arr[n];
for(int i = 0;i<n;i++){
scanf("%d",&arr[i]);
}
scanf("%d",&d);
scanf("%c",&k);
if(k == 'L'){
rotLeft(arr,n,d);
}
else{
rotRight(arr,n,d);
}
for(int i = 0;i<n;i++){
printf("%d ",arr[i]);
}
return 0;
}```
when i run my code in an online compiler it seems to work as intended but in the platform where im expected to submit the solution the output seems different
#im trying to rotate an input array by d places either to the left or the right
14 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
well
since i didnt get an answer from here earlier, so i jus asked chatgpt and it said im incorrectly handling the character input for k
it suggested i do scanf(" %c",&k) instead of scanf("%c",&k)
it worked after adding that space
Yeah AI is like the last thing you want to debug your code.