Question: C + + Replace every element with its previous element Given an array of integers, replace each element in the array by the previous element.

C++
Replace every element with its previous element
Given an array of integers, replace each element in the array by the previous element.
Replace the first element by -1.
Write a function:
void replaceElements(int array[], int size) that accepts an array and the size of the array.
Parameters:
array ={1,2,3,4}
size =4
Output
-1123
Explanation: Every element A[i] is replaced by A[i-1]. And the first element will be -1, as the first element doesn't have any previous element.
You only need to write the function. A main program will be provided which will call your function, and print the array contents after your function ends.
C + + Replace every element with its previous

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!