Write C++ statements to: Explain pls 1) Declare two arrays named myArraya and yo
ID: 3832392 • Letter: W
Question
Write C++ statements to: Explain pls
1) Declare two arrays named myArraya and yourArray with capacity to store up to 100 whole numbers.
2) Fill myArray according to the following rules:
A) the first element of the array gets a value equal to the current index
B) the rest of the elements get the value of the previous element plus a value equal to the current index
3) Fill yourArray with the values from myArray in reverse order. Declare any additional variables you need.
Example:
0 1 3 6 10 15 21 28 36 45 55 66 78 91 105 120 136 153 171 190
190 171 153 136 120 105 91 78 66 55 45 36 28 21 15 10 6 3 1 0
Explanation / Answer
Sorry for mistake this is the desired code in c++:
void ArrayProgramChegg::main(std::vector<std::wstring> &args)
{
std::vector<int> myArray(100); //as per question capacity of 100 whole
std::vector<int> yourArray(100); //as per question capacity of 100 whole
int n, i, j = 0;
Scanner *scan = new Scanner(System::in); // object of scanner class
std::wcout << L"eneter size of array :";
n = scan->nextInt();
myArray[0] = 0; //inserting first element zero
for (i = 1; i < n; i++) //loop for inserting values in myArray
{
myArray[i] = myArray[i - 1] + i;
}
for (i = n - 1; i > 0; i--) //reverse loop for inserting elements in yourArray
{
yourArray[j] = myArray[i];
j++;
}
std::wcout << L"Elements in myArraya is : "; //printing values in of myArray & youe Array
for (i = 0; i < n; i++)
{
std::wcout << myArray[i] << L" ";
}
std::wcout << L" Elements in youArraya is : ";
for (i = 0; i < n; i++)
{
std::wcout << yourArray[i] << L" ";
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.