Answer to Question #341175 in C++ for Minahil

Question #341175

Write a program that accepts 10 integer values from iser in an array and passes array and its size to a function . The function makes the odd values stored in the array 2- times the updated array is displayed by main().

1
Expert's answer
2022-05-15T16:59:45-0400


#include <iostream>
#include <iomanip>
using namespace std;
void doubleOdd(int *arr,int &size)
{
  int i=0;
  while(i<size)
    {
      if(arr[i]%2)//if it is odd number
      {
        for(int j=size;j>i;j--)
          arr[j]=arr[j-1];
        size++;
        i++;
      }
      i++;
    }
}
int main()
{
  int size;
  cout<<"Please input size:";
  cin>>size;
  int *ar=new int[size];
  for(int i=0;i<size;i++)
    cin>>ar[i];
  doubleOdd(ar,size);
  cout<<"\nUpdated array ===============\n\n";
  for(int i=0;i<size;i++)
    cout<<setw(5)<<ar[i]<<" ";
  cout<<endl;
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS