Created
September 21, 2016 15:06
-
-
Save AndyNovo/774765176f9292cdedd72869e6c45f89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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