write a c++ program that takes array values as an input .for each array element, find the difference between that element and last array element and update the array.
array can be of any size.
example:
input array: 1, 4, 5, 6, 7, 2
#include <iostream>
using namespace std;
int main()
{
int size = 0;
cout << "Enter size of Array: ";
cin >> size;
int* a = new int[size];
cout << "Enter Array's elements to separate values use spaces." << endl;
cout << "Input array: ";
for (int i = 0; i < size; i++)
{
cin >> a[i];
}
cout << "Updated array: ";
for (int i = 0; i < size; i++)
{
a[i] -= a[size - 1];
cout << a[i] << " ";
}
cout << endl;
return 0;
}
Comments
Leave a comment