A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C++ program to update every array element by multiplication of next and previous values of a given array of integers
Q:

Write a C++ program to update every array element by multiplication of next and previous values of a given array of integers

0

Write a C++ program to update every array element by multiplication of next and previous values of a given array of integers

Sample Output:

Original array: 0 1 3 4 5 6 7 8 10 
New array elements: 0 0 4 15 24 35 48 70 80

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;
 
void replace_elements(int nums[], int n)
{
    if (n <= 1)
      return;
 
    int prev_element = nums[0];
    nums[0] = nums[0] * nums[1];
 
    for (int i=1; i<n-1; i++)
    {
        int curr_element = nums[i];
 
        nums[i] = prev_element * nums[i+1];
 
        prev_element = curr_element;
    }
 
    nums[n-1] = prev_element * nums[n-1];
    }
 
int main()
{
    int nums[] = {0, 1, 3, 4, 5, 6, 7, 8, 10};
    int n = sizeof(nums)/sizeof(nums[0]);
   	cout << "Original array: ";
    for (int i=0; i < n; i++) 
    cout << nums[i] <<" ";
    replace_elements(nums,n);
    cout << "\nNew array elements: ";
    for (int i=0; i < n; i++) 
      cout << nums[i] <<" ";
  return 0;     

}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now