Skip to content

Instantly share code, notes, and snippets.

@AndyNovo
Created September 21, 2016 15:06
Show Gist options
  • Select an option

  • Save AndyNovo/774765176f9292cdedd72869e6c45f89 to your computer and use it in GitHub Desktop.

Select an option

Save AndyNovo/774765176f9292cdedd72869e6c45f89 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(){
srand(time(0));
int even = 0;
int odd = 0;
int i=0;
int x, xm2 = 0;
for(; i < 3; i++){
x = rand();
xm2 = x % 2;
if (xm2 = 0){
even++;
} else {
odd++;
}
}
cout << "After " << i << " trials of rand() found " << even << " evens and " << odd << " odds" << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment