Evens And Odds in C++
Posted by Samath
Last Updated: May 21, 2015

Create an EvensAndOdds application that generates 25 random integers between 0 and 99 and then displays all the evens on one line and all the odds on the next line. Application output should look similar to:

ODD:21 87 39 45 7 75 71 87 9 81 27 57

EVEN: 26 64 2 74 0 40 84 0 82 0 32 90

Solution:

#include <iostream>
#include <ctime>
#include <cstdlib>

using namespace std;
int main(int argc, char *argv[])
{
	 int number[25];
	 
	 srand(time(NULL));
	 
	 for(int i =0;i<25;i++)
	 {
	 	number[i] = rand()%99;
	 }
	 
	 cout<<"EVEN: ";
	 
	 for(int i =0;i<25;i++)
	 {
	 	if(number[i]%2==0)
	 	{
	 		cout<<number[i]<<" ";
	 	}
	 }
	 
	 	 cout<<"\nODD: ";
	 
	 for(int i =0;i<25;i++)
	 {
	 	if(number[i]%2!=0)
	 	{
	 		cout<<number[i]<<" ";
	 	}
	 }
	return 0;
}

 

Related Content