ahmed0saber

Converting array into two even-or-odd arrays in C++

May 30th, 2021
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int _array[5]={3,7,2,5,8} , _even[5] , _odd[5] , num=0 , num2=0;
  6.     for(int i=0;i<5;i++)
  7.     {
  8.         if(_array[i]%2==0)
  9.         {
  10.             _even[num]=_array[i];
  11.             num++;
  12.         }
  13.         else
  14.         {
  15.             _odd[num2]=_array[i];
  16.             num2++;
  17.         }
  18.     }
  19.     cout<<"even numbers\n";
  20.     for(int j=0;j<5;j++)
  21.     {
  22.         cout<<_even[j]<<endl;
  23.     }
  24.     cout<<"\n\n\nodd numbers\n";
  25.     for(int k=0;k<5;k++)
  26.     {
  27.         cout<<_odd[k]<<endl;
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment