/* Function to rotate the elements of an array right by one position. */ #include #include /* Implement the rotate function inside the declaration below. */ void rotate(int nums[], int n) { /* BEGIN ANSWER -- do not delete this line */ /* END ANSWER -- do not delete this line */ } /* DO NOT ALTER THE main PROGRAM */ int main(void) { int numbers[100]; int count=0; int newval = 1, i; printf("Enter a list of (at most 100) positive integers,\nseparated by space or newlines.\n"); printf("Use a 0 or a negative int "); printf("to indicate you are finished.\n"); while ((count < 100) && (newval >0)) { scanf("%d", &newval); if (newval>0) { numbers[count] = newval; count++; } } if (count == 0) printf("\nNo positive numbers entered.\n"); else { rotate(numbers, count); printf("\nYour list has been rotated one position. It is now: \n"); for (i=0; i < count; i++) printf("%d ", numbers[i]); } printf("\n"); return EXIT_SUCCESS; }