Answer to Question #203659 in C++ for hadia farooq

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


1
Expert's answer
2021-06-05T23:53:03-0400
#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!

Comments

abiha
26.12.21, 11:07

soooooooooooo helpful thanks

Leave a comment

LATEST TUTORIALS
New on Blog