Write a function that removes all even numbers from an array. The function shoul
ID: 3790446 • Letter: W
Question
Write a function that removes all even numbers from an array. The function should take the array, length of the array, and a pointer for number of odd numbers found as arguments and return a pointer to the new array. If there are no odd numbers found in the array, your code should print "No odds found." and return NULL Use the function header: int removeEvens(int a, int length, int oddsFound); Example: Input array 13, 4, 5, 6, 7) *oddsFound 3 return array 13, 5, 7) The size of the return array needs to be the number of odd numbers found. Note: You cExplanation / Answer
ANSWER TO FIRST QUESTION
#include<iostream.h>
#include<conio.h>
int* removeEvens(int *a,int length, int *oddsFound)
{
int *odd_arr;
odd_arr=new int[*oddsFound];
int c=0;
for(int i=0;i<length;i++)
{
if(a[i]%2!=0)
{
odd_arr[c]=a[i];
c++;
}
}
return odd_arr;
}
void main()
{
int odd=0;
int a[50];
int n;
int *p;
clrscr();
cout<<"enter the number of elements"<<endl;
cin >> n;
for(int i=0;i<n;i++)
cin >> a[i];
for(int j=0;j<n;j++)
{
if(a[j]%2!=0)
{
odd=odd+1;
}
}
p=removeEvens(a,n,&odd);
cout<<"the content of odd array are"<<endl;
for(int k=0;k<odd;k++)
cout<<" "<<p[k];
getch();
}
ANSWER TO THE SECOND QUESTION
option c is the answer. 10 8 10 8 10 will be the contents of the array. after executing that code.
answer to third question
option d is not the valid function call.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.