Posted by MindBreaker at 1:44 AM
Read our previous post
Object:
4. Find all the even and odd
numbers in an array
Source Code;
// EVEN
ODD NUMBERS
#include <iostream>
using namespace std;
class
average
{
public:
int
even,odd,count,elementeven[10],elementodd[10];
int
*sepeven( int ary[10])
{
for(count=0;count<10;count++)
{
if(ary[count]%2==0)
{
even=ary[count];
elementeven[count]=even;
}
}
return
elementeven;
}
int
*sepodd( int ary[10])
{
for(count=0;count<10;count++)
{
if(ary[count]%2!=0)
{
odd=ary[count];
elementodd[count]=odd;
}
}
return
elementodd;
}
};
void
main()
{
average avg;
int
i,arry[10],*retrneven,*retrnodd;
cout<<"Enter
numbers in array : \n";
for(i=0;i<10;i++)
{
cin>>arry[i];
}
retrneven=avg.sepeven(arry);
retrnodd=avg.sepodd(arry);
for(i=0;i<10;i++)
{cout<<"Even
number are : "<<retrneven[i]<<endl;
cout<<"Odd
number are : "<<retrnodd[i]<<endl;
}
}
}
Output:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.