1.

Write a function in C++, which accepts an integer array and its size as arguments and replaces elements having odd values with thrice its value and elements having even values with twice its value. Example: if an array of nine elements initially contains the elements as 3, 4, 5, 16, 9 then the function should rearrange the array as 9, 8, 15, 32, 27

Answer»

void RearrangeArray(int A[],int size)

{

for(int i=0;i<size;i++)

{ if(A[i]%2==0)

A[i]*=2;

else

A[i]*=3;

}

}



Discussion

No Comment Found

Related InterviewSolutions