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().
#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;
}
Comments
Leave a comment