Untitled
unknown
plain_text
2 years ago
573 B
13
Indexable
int array_left(int* arr,int size,int steps){
int *temp = (int *)malloc(size * sizeof(int));
if (temp == NULL) {
printf("Memory allocation failed.\n");
return -1;
}
// Initialize all elements to zero
for (int i = 0; i <size; i++) {
temp[i] = arr[i];
}
int i;
int new_index;
for(i=0;i<size;i++){
if((i-steps)>=0){
new_index=i-steps;
}
else{
new_index=i-steps+size;
}
arr[new_index]=temp[i];
}
free(temp);
return 1;
}Editor is loading...