mardi 12 novembre 2019

Separating and printing out the even and odd random numbers

I have generated 100 random numbers, where I have to shorted out equal even and odd numbers of the random numbers. All even or odd numbers can not be repetitive.

For example I will create 100 random numbers

#include <iostream>   
#include <cstdlib>    

int main()
{
  for (int i=1; i <=100; ++i){

      //double p = rand();
      std::cout <<"random number is :" << rand()<<std::endl;


  }


}

Since I don't know if the even and odd numbers are same in the list from the 100 random numbers, I want to pick minimum number of pair even and odd numbers. I also will like to know what the total odd and even numbers are generated separately. One note is that, if for an example, any even or odd number get printed out multiple times, I want to consider that as a one.

For example. Let's assume we have 60 even and 40 odd numbers from the printed random numbers. The printed out numbers would be first 20 even numbers and first 20 odd numbers.

The reason I want to do this is because I want to learn How I can filter out the even and odd numbers from the for loop of random generator.




Aucun commentaire:

Enregistrer un commentaire