69,373
社区成员
发帖
与我相关
我的任务
分享
void change(int *pointer[M]){
int i;
int temp[N];
for(i=0; i<N; i++) temp[i]=*pointer[M-N+i];
for(i=M-1; i>N-1; i--) *pointer[i]=*pointer[i-N];
for(i=0; i<N; i++) *pointer[i]=temp[i];
}
# include<stdio.h>
# define M 6
# define N 2
void input(int num[]);
void change(int *pointer[]);
int main(){
int num[M];
int i;
int *p[M];
for(i=0; i<M; i++) p[i]=num[i];
input(num);
printf("what you input:\n");
for(i=0; i<M; i++) printf("%d\t", num[i]);
putchar('\n');
change(p);
printf("after change:\n");
for(i=0; i<M; i++) printf("%d\t", p[i]);
return 0;
}
void input(int num[]){
int i;
printf("input a string of numbers:\n");
for(i=0; i<M; i++){
if(!i) printf("input the 1st number:\n");
else if(1==i) printf("input the 2nd number:\n");
else if(2==i) printf("input the 3rd number:\n");
else printf("input the %dth number:\n", i+1);
scanf("%d", &num[i]);
}
}
void change(int *pointer[M]){
int i;
int temp[N];
/*
for(i=0; i<N; i++){
*temp=*pointer[i];
*pointer=*pointer[M-N+i];
*pointer[M-N+i]=*temp;
}
*/
for(i=0; i<N; i++) temp[i]=*pointer[M-N+i];
for(i=M-1; i>N-1; i--) *pointer[i]=*pointer[i-N];
for(i=0; i<N; i++) *pointer[i]=temp[i];
}