#include<iostream>
using namespace std;
void subtitutesElements(int arr[], int size)
{
if (size <= 1)
return;
int previous = arr[0];
arr[0] = arr[0] * arr[1];
for (int i=1; i<size-1; i++)
{
int current = arr[i];
arr[i] = previous * arr[i+1];
previous = current;
}
arr[size-1] = previous * arr[size-1];
}
int main()
{
int arr[] = {0, 1, 3, 4, 5, 6, 7, 8, 10};
int size = sizeof(arr)/sizeof(arr[0]);
cout << "Initial Array array: ";
for (int i=0; i < size; i++)
cout << arr[i] <<" ";
subtitutesElements(arr,size);
cout << "\nNew Array: ";
for (int i=0; i < size; i++)
cout << arr[i] <<" ";
return 0;
}
Comments
Leave a comment