Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 17: Write a C++ program to update every array element with the multiplication of previous and next numbers of array.

#include<iostream>
using namespace std;
int main()
{
	int size=0;
	cout<<"\nenter the size of an array : ";
	cin>>size;
	int arr[size],arr1[size];

	cout<<"\nenter the elements of an array : ";
	for(int i=0;i<size;i++)
	{
		cin>>arr[i];
	}

	for(int i=0;i<size;i++)
	{
		if(i==0)
		arr1[i]=arr[i+1];
		else if(i==(size-1))
		arr1[i]=arr[i-1];
		else
		arr1[i]=arr[i-1]*arr[i+1];
	}

	cout<<"\nnew array after rearrange :\n";
	for(int i=0;i<size;i++)
	{
		cout<<arr1[i]<<"\t";
	}
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.