Declare an integer array of size 10 with values initialized as follows.
int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
Compute each item of a new array of same size derived from the above array by:
adding first item (intArray[0]) of the array with 3rd, 2nd with 4th, 3rd with 5th and so on. For the last-but-one item intArray[8], add it with first item and for the last item (intArray[9]) add it with 2nd item (treat it as a circular array).
Print all items of the new array in a single line.
#include <iostream> using namespace std; int main() { int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; int n1 = intArray[0], n2 = intArray[1], size = 10; for (int i = 0; i < size-2; ++i) { intArray[i] += intArray[i+2]; } intArray[size-1] += n1; intArray[size-2] += n2; for (int i = 0; i < size; ++i) { cout << intArray[i] << " "; } cout << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.