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;
}
Get Answers For Free
Most questions answered within 1 hours.