Question

# Write a program in c++ to Convert an array of inches to an array of centimeters....

Write a program in c++ to Convert an array of inches to an array of centimeters. The program should contain a function called inchesTOcm with three parameters (inches array that contains the values in inches, cm array to save the result in, and an integer variable that defines the length of the array). In the main function: 1. Define an array (inches) of length 3.
2. Initialize the array by asking the user to input the values of its elements.
3. Define an array (cm) of the same length to save the results in it.
4. Call the function inchesTOcm.
5. Print the values of the cm array. Hint: to convert from inches to cm multiply the value by 2.54

Here is the full code as per the instructions given in the question with comments

The arrays are float because the user can enter float values and it will work for integer values also.

#include <iostream>

using namespace std;
float inchestocm(float array[],float cmarray[],int n) // function to change inches to cm
{ int i;
for (i=0;i<n;i++)
{
cmarray[i]=2.54*array[i]; // multiplying every element of incharray by 2.54

}
}

int main() // main function
{
float array[3]; // array of inches
int i;
float cmarray[3]; // array to store the cm values
for (i=0;i<3;i++)
{
cout<<"Enter the element "<<"" <<i <<"\n";
cin>>array[i]; // taking the input from the user
}

inchestocm(array,cmarray,3); // function call with 3 parameter

for (i=0;i<3;i++) // loop to iterate every element of cmarry
{
cout<<" The values in the cm are ";
cout<<cmarray[i] <<"cm"<<"\n"; // printing the Cm array
}

return 0;
}

#### Earn Coins

Coins can be redeemed for fabulous gifts.