Hi,
in this code I'm trying to make a function that will perform a circulated shift of the numbers in an array, for example:
123 become 312
I have a bug in the code that I don't find !
(the user give the times for shifting)
thank for the helpers
Code:#include<stdio.h> void shift_to_end(int array[],int size) { int i = 0, temp = 0; for(i = size; i > 0 ; --i) { temp = array[i]; array[i] = array[i-1]; array[0] = temp; } } #define ARRAY_SIZE 10 int main() { int numbers[ARRAY_SIZE]; int i = 0, shift = 0 ; printf("Please enter 10 numbers:\n"); for (i = 0; i < ARRAY_SIZE ; ++i) scanf(" %d", &numbers[i]); printf("please enter times to shift\n"); scanf("%d", &shift); for (i=1; i <= shift; ++i); shift_to_end(numbers, ARRAY_SIZE); /* print the shifted array */ for (i = 0; i < ARRAY_SIZE; ++i) printf("%d", numbers[i]); return 0; }



LinkBack URL
About LinkBacks


