08/01/27 19:38:22
>>664
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ARRAY_SIZE 32
void shift(int *p, int v) {
int *buf = (int*)malloc(sizeof(int)*v+1);
memcpy(buf, p, sizeof(int)*v);
memmove(p, p+v, sizeof(int)*ARRAY_SIZE);
memcpy(p+(ARRAY_SIZE-v), buf, sizeof(int)*v);
}
void print(int *p) {
int i = 0;
printf("array[%d] = {", ARRAY_SIZE);
do {
printf("%d", p[i]);
} while (++i < ARRAY_SIZE && putchar(','));
printf("}\n");
}
int main () {
int i, in, array[ARRAY_SIZE];
for (i = 0; i < ARRAY_SIZE; ++i) array[i] = i;
print(array);
scanf("%d", &in);
shift(array, in%=ARRAY_SIZE);
print(array);
shift(array, ARRAY_SIZE-in);
print(array);
return 0;
}