how to display new array
how can i display the array after i edit the index of the array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
// Listing4.2.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
using namespace std;
constexpr int Square(int number) { return number * number; }
int main()
{
const int ARRAY_LENGTH = 5;
// Array of 5 integers, initialized using a const
int myNumbers[ARRAY_LENGTH] = { 5, 10, 0, -101, 20 };
// Using a constexpr for array of 25 integers
int moreNumbers[Square(ARRAY_LENGTH)];
cout << "Enter index of the element to be changed: ";
int elementIndex = 0;
cin >> elementIndex;
cout << "Enter new value; ";
int newValue = 0;
cin >> newValue;
myNumbers[elementIndex] = newValue;
moreNumbers[elementIndex] = newValue;
cout << "Element " << elementIndex << " in array myNumbers is: ";
cout << myNumbers[elementIndex] << endl;
cout << "Element " << elementIndex << " in array moreNumbers is: ";
cout << moreNumbers[elementIndex] << endl;
cout << myNumbers << endl;
cin.get();
return 0;
}
| |
thank you
for(int i = 0; i < ARRAY_LENGTH; i++)
cout << myNumbers[i] << " ";
cout << endl;
thank you!
that works!
Topic archived. No new replies allowed.