This article is a mirror article of machine translation, please click here to jump to the original article.

View: 14433|Reply: 0

[C] The pointer method has N integers, so that the previous numbers move back M positions in order, and finally the M number becomes the previous M number

[Copy link]
Posted on 12/15/2015 4:40:22 PM | | |
There are N integers, so that the order of the previous numbers is moved back M positions, and finally M numbers become the M numbers in front, write a function to achieve the above functions, enter N integers N integers and output adjusted N numbers in the main function.

#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
{void move(int array[20],int n,int m);
int number[20],n,m,i;
printf("how many numbers?");
scanf("%d",&n);
printf("input %d numbers:\n",n);
for(i=0; i<n; i++)
scanf("%d",&number[i]);
printf("how many place you want move?");
scanf("%d",&m);
move(number,n,m);
printf("now ,they are:\n");
for(i=0; i<n; i++)
printf("%d  ",number[i]);
printf("\n");
return 0;
}
void move(int array[20],int n,int m) // function that moves back once in a loop
{int *p,array_end;
array_end=*(array+n-1);
for(p=array+n-1; p>array; p--)
    *p=*(p-1);
    *array=array_end;
    m--;
    if(m>0) move(array,n,m);       Recursive call, when the number of loops M is reduced to 0, the call is stopped
}






Previous:After learning the pointer for several days, what is it used for, and why does he use it?
Next:C language shares national secret algorithm SMS4 block symmetric cryptographic algorithm
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com