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
#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;
}
Comments
soooooooooooo helpful thanks
Leave a comment