Question #20274

find even and odd numbers from n integers

Expert's answer

#include <stdio.h>

#include <iostream.h>

bool odd(int a){

if (a%2!=0) return true;

else return false;

}

void main()

{

int b[9999], n, i;

cout<<"how many integers do you want to set? ";

cin>>n;

cout<<"enter "<<n<<" integers: ";

for (i=0;i<n;i++) cin>>b[i];

cout<<"\neven:\n";

for (i=0;i<n;i++) if(!odd(b[i])) cout<<b[i]<<" ";

cout<<"\n";

cout<<"\nodd:\n";

for (i=0;i<n;i++) if(odd(b[i])) cout<<b[i]<<" ";

cout<<"\n";

}

#include <iostream.h>

bool odd(int a){

if (a%2!=0) return true;

else return false;

}

void main()

{

int b[9999], n, i;

cout<<"how many integers do you want to set? ";

cin>>n;

cout<<"enter "<<n<<" integers: ";

for (i=0;i<n;i++) cin>>b[i];

cout<<"\neven:\n";

for (i=0;i<n;i++) if(!odd(b[i])) cout<<b[i]<<" ";

cout<<"\n";

cout<<"\nodd:\n";

for (i=0;i<n;i++) if(odd(b[i])) cout<<b[i]<<" ";

cout<<"\n";

}

## Comments

## Leave a comment