Write a program that uses three arrays ‘A’, ‘B’, and ‘C’. It inputs integer values in array ‘A’. In second array ‘B’, it stores the squares of values of array ‘A’ and in third array ‘C’, it stores cubes of the values of ‘A’. The program should display the contents of three arrays, i.e. ‘A’, ‘B’, and ‘C’.
Suppose array ‘A’ has values: 2, 3, 5, 6, 7
The values of ‘B’ should be: 4, 9, 25, 36, 49
The values of ‘C’ should be: 8, 27, 125, 216, 343
So let’s Write Code:
Code:
Write a program that uses three arrays ‘A’, ‘B’, and ‘C’. It inputs integer values in array ‘A’. In second array ‘B’, it stores the squares of values of array ‘A’ and in third array ‘C’, it stores cubes of the values of ‘A’.
#include<iostream>
using namespace std;
main()
{
long A[5], B[5], C[5], i;
i = 0;
while(i<=4)
{
cout<<"Enter value in element "<<i<< " of array A ? ";
cin>>A[i];
B[i] = A[i] * A[i];
C[i] = A[i] * A[i] * A[i];
i++;
}
cout<<"Array A \t Array B \t Array C "<<endl;
i = 0;
while(i<=4)
{
cout<<A[i]<<'\t'<<B[i]<<'\t'<<C[i]<<endl;
i++;
}
}
Hope You will learn Something. Happy Coding.
Visit my YouTube Channel as Well😇 https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4
Click on the below Links for more Programming Exercises:
Conditional Structure Exercises: 👉https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/
Array Exercises: 👉https://myustaadg.com/category/programming-exercises/arrays-exercises/