Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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)
#include<iostream>
using namespace std;
int main()
{
    int array[10],odd[10],even[10],i,n,j=0,k=0;
    cout<<"enter size of array ";
    cin>>n;
      
    for(i=0;i<n;i++)                   //inserting element in array
    {
            cin>>array[i];
     }
    for(i=0;i<n;i++)
    {
         if(array[i]%2==0)                 // logic to find even
          { even[j]=array[i];
             j++;
          }
         else
          {                                
               odd[k]=array[i];
               k++;
          }

    }
 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)
Hi!

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)
ohhh...
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.
...