what is the problem with this code that i'm mentioning ? not giving correct output ..

+1 vote
asked Jul 11, 2018 by manish (170 points)
using namespace std;
int main()
    int array[10],odd[10],even[10],i,n,j=0,k=0;
    cout<<"enter size of array ";
    for(i=0;i<n;i++)                   //inserting element in array
         if(array[i]%2==0)                 // logic to find even
          { even[j]=array[i];

 cout<<"even : ";                                               //printing even array
 for(i=0;i<j;i++) {cout<<even[j]<<" ";}
 cout<<"odd : ";                                                //printing odd array
 for(i=0;i<k;i++) {cout<<odd[k]<<" ";}
 return 0;

1 Answer

–1 vote
answered Jul 11, 2018 by marius (140 points)

the output instructions should be like for(i=0;i<j;i++) cout<<even[i]<<" "; and for(i=0;i<k;i++) cout<<odd[i]<<" ";

i replaced "j' and "k" in cout<<even[j]/odd[k]  with "i" because you want to show, for example the even array, from i=0 (first position in the array) to i=j-1 (last position in the array)
commented Jul 11, 2018 by manish (170 points)
it was a stupid mistake
anyway thank you …..
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.