Answer to Question #4001 in C++ for vaish

Question #4001
Write a c++ program from lists to input 10 numbers & store them in the list.from the list create two more list one containing even numbers another containing odd numbers.Output all three lists.
1
Expert's answer
2012-03-20T12:02:29-0400
C++
Write a c++ program from lists to input 10 numbers & store them in the list. from the list create two more list one containing even numbers another containing odd numbers. Output all three lists.

# include<iostream.h>
# include<conio.h>

int i;
int num[10], odd[10], even[10];
int numodd=0, numeven=0;

bool checkodd(int a){
if (a%2==0) return 0;
else return 1;
}

void main(){
for (i=0;i<=9;i++){
& cout<<"Enter a number: ";
& cin>>num[i];
}

for (i=0;i<=9;i++){
& if (checkodd(num[i])==1){
& odd[numodd] = num[i];
& numodd++;
& }
& else{
& even[numeven] = num[i];
& numeven++;
& }
}

numodd--;
numeven--;
cout<<"Initial list:\n";
for (i=0;i<=9;i++){
& cout<<num[i]<<" ";
}
cout<<"\nList of odds:\n";
for (i=0;i<=numodd;i++){
& cout<<odd[i]<<" ";
}
cout<<"\nList of evens:\n";
for (i=0;i<=numeven;i++){
& cout<<even[i]<<" ";
}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS