有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数.写一函数实现以上功能,在主函#include "stdio.h"#include "stdlib.h"void move(int*,int,int);void main(){int *p,x,n;register int i;printf("请输

来源:学生作业帮助网 编辑:作业帮 时间:2024/10/03 14:58:22
有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数.写一函数实现以上功能,在主函#include
xn0_ %rM>/Х)Xj+-S`B`ck'Nh Hv^&N+^' ҸC"':?cUV;|}W|iLH!6yk^m:hCIbop,,oη ws7-BꣲZL̥RJVMRF˄sB)X/*+k 6K@juBF ̂EpZ]i1Ԣ@"5|Ҙ)\N72UIIV`]hlYmT\#OtiJbZ2Y[ j "ӻ7AlŽZ@-"O[ 낍Y$E[1jd-]+%S5_c%ZL&$=-}a~B$p~w0;~%xv]Ɂȷ7Hx{r4}eV2Ek(+X7\q)׷ 6W

有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数.写一函数实现以上功能,在主函#include "stdio.h"#include "stdlib.h"void move(int*,int,int);void main(){int *p,x,n;register int i;printf("请输
有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数.写一函数实现以上功能,在主函
#include "stdio.h"
#include "stdlib.h"
void move(int*,int,int);
void main()
{
int *p,x,n;
register int i;
printf("请输入的数据大小(n):");
scanf("%d",&n);
p=(int *)malloc(sizeof(int)*n);
for(i=0;i

有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数.写一函数实现以上功能,在主函#include "stdio.h"#include "stdlib.h"void move(int*,int,int);void main(){int *p,x,n;register int i;printf("请输
void move(int*p,int n,int x)
{
int *pTemp=(int *)malloc(sizeof(int)*n);
memcpy(pTemp,p + n - x,sizeof(int)*x);
memcpy(pTemp+x,p,sizeof(int)*(n-x));
memcpy(p,pTemp,sizeof(int)*n);
free(pTemp);
}

这是c语言吗,计算机语言的弱点之一,一旦出错,很难发现

void move(int*p,int n,int x)
{
int *pTemp=(int *)malloc(sizeof(int)*n);
memcpy(pTemp, p + n - x, sizeof(int)*x);
memcpy(pTemp+x, p, sizeof(int)*(n-x));
memcpy(p, pTemp, sizeof(int)*n);
free(pTemp);