Computer Science, asked by subho6743, 1 year ago

Write and call a function in c++ which accepts an integer array and its size as arguments and replaces elements having even values with its half and elements having odd values with twice its value. example : if an array of five elements initially contains the elements as 3, 4, 5, 16, 9 then the function should rearrange the content of the array as 6, 2, 10, 8, 18.

Answers

Answered by Anonymous
0
call a function in c++ which accepts an integer array and its size as arguments and replaces elements having even values with its half and elements having odd values with twice its value. example : if an array of five elements initially contains the elements as 3, 4, 5, 16, 9 then the function should rearrange the content of the array as 6, 2, 10, 8, 18.

is given below
.........




------------. void accep. ----------.




**********. (int a[ ],int size)



{




for

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



{


● if (a[i]%2= =0)



a[i]=a[i]/2;





else




a[i]=a[i]*2;





cout<<a[i]



<



<


<

<


<



}




}
Similar questions