Question #203659

Write a C++ program that creates two one dimensional arrays “A” and “B” of size 20 elements each. The main program should get the input in the array “A” from the user and initialize array “B” with values “0”. Your program should calculate the (number -2) of each element of array “A” and should store in the square value in corresponding positions (index) in the array “B”. In the end, the main program (main function) prints the calculated values of array “B”. Also display the values in array B which are Odd


Expert's answer

#include <iostream>

int a[20], b[20];

int main() 
{
  for (int i = 0; i < 20; i++) {
    std::cin >> a[i];
    b[i] = (a[i] - 2) * (a[i] - 2);
    if (b[i] % 2)
      std::cout << b[i] << " ";
  }
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS