Home > Back-end >  An array of C programming problem urgent request
An array of C programming problem urgent request

Time:04-14

6. Translation array: an array a known entities n integers, requirements from 0 to the subscript p array element
Translation to the end of the array,
Requirements:
Input:
There are two lines, line 1 is two integer n (n 1000) or less and p (p n1) or less, respectively array element number
And the subscript p, line 2 is an array of n integers,
Output:
Only a line, element array after translation. A, separated by Spaces between data,
The sample input:
5 2
2 4 July 1 5
The sample output:
1 5 2 4 7

CodePudding user response:

refer to the original poster novice fledglings response:
6. Translation array: an array with n integers, known requirements from 0 to the subscript p array element
Translation to the end of the array,
Requirements:
Input:
There are two lines, line 1 is two integer n (n 1000) or less and p (p n1) or less, respectively array element number
And the subscript p, line 2 is an array of n integers,
Output:
Only a line, element array after translation. A, separated by Spaces between data,
The sample input:
5 2
2 4 July 1 5
The sample output:
1 5 2 4 7

Hurry to rush for urgent request

CodePudding user response:

Reference:
 # include 

Arr void move_arr (int * and an int p, int n);

Int main ()
{
Int n, p, I;
The scanf (" % d % d ", & amp; N, & amp; P);

Int * a=new int [n].

for(i=0; iThe scanf (" % d ", & amp; A [I]);

Move_arr (a, p, n);

for(i=0; iPrintf (" % d ", a [I]);

The delete [] a;
return 0;
}

Arr void move_arr (int * and an int p, int n)
{
Int I, k=0, * ap=new int [n].
for(i=0; iAp [I]=arr [I];
For (I=p + 1; iArr [k++]=arr [I];
for(i=0; i<=p; I++)
Arr=[k++] ap [I];
The delete [] ap;
}
  • Related