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
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]
<
<
<
<
<
}
}
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
Math,
6 months ago
Computer Science,
6 months ago
Physics,
6 months ago
English,
1 year ago
Chemistry,
1 year ago
Physics,
1 year ago
Political Science,
1 year ago
Math,
1 year ago