Ask your own question, for FREE!
Computer Science 10 Online
OpenStudy (anonymous):

program in c++ using array that determine odd and even numbers from input numbers. sample run: enter 10 int: 1 2 3 4 5 6 7 8 9 10 odd: 1 3 5 7 9 even; 2 4 6 8 10

OpenStudy (konradzuse):

I will explain. In C++ you should have something called a Module or Mod also known as the symbol %. Using your C++ knowledge(which you should have) you should be able to do this. if(i % 2 == 0) //even else if (i% 2 == 1) //odd It's that simple.

OpenStudy (konradzuse):

i is an integer, so for example 2 % 2 = 0 is even and 3 % 2 = 1 is odd.

OpenStudy (konradzuse):

basically the % will be a remainder #. So 3/2 is 1 remainder 1. 26 % 2 is 13 remainder 0, and 29 % 2 is 14 remainder 1. Make sense?

OpenStudy (anonymous):

yep i got it. i already made a program. but idk if it is correct lol.

OpenStudy (anonymous):

#include "stdafx.h" #include <iostream> using namespace std; const int ARRAY_SIZE = 10; int item[ARRAY_SIZE]; int counter; int _tmain(int argc, _TCHAR* argv[]) { cout<<"Please enter 10 no.: "; for(counter = 0;counter<10;counter++) { cin>>item[counter]; } cout<<endl<<endl; cout<<"The even no. are: "; for (counter = 0;counter<10;counter++) { if(item[counter] %2==0) { cout<< item[counter]<< " "; } } cout<<endl<<endl; cout<<"The odd no. are: "; for (counter = 0;counter<10;counter++) { if(item[counter] % 2!=0) { cout<<item[counter] << " "; } } system("pause"); return 0;

OpenStudy (konradzuse):

only way to know is to try it out ;)

OpenStudy (konradzuse):

also you want 1 for loop. having 2 is redundant....

OpenStudy (konradzuse):

for (counter = 0;counter<10;counter++) { if(item[counter] % 2 == 0 { //Even } else If //etc { //odd }

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!