Demonstrates the generation of random number in three different
ranges:
03 through 07
20 through 50
-6 through 15
Source Code:
Result:
ranges:
03 through 07
20 through 50
-6 through 15
Source Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <iostream.h> #include <conio.h> #include <cstdlib> using namespace std; int main () { cout << " Enter random number seed: "; int seed; cin >> seed; srand ( seed ); cout << " Random number with seed " << seed <<" : " << rand () << " " << rand () << " " << rand () << " " << rand () << "\n\n\n"; cout << " Enter another random seed:"; cin >> seed ; srand ( seed ); cout << " Random numbers with seed " << seed << " : " << rand () << " " << rand () << " " << rand () << " " << rand () << "\n\n"; cout << " Enter another random seed:"; cin >> seed ; srand ( seed ); cout << " Random numbers with seed " << seed << " : " << rand () << " " << rand () << " " << rand () << " " << rand () << "\n\n"; cout << " Hope you found these numbers intresting!!! :)\n "; getch (); return 0; } // main |
Result:
Range 03 to 07: 5 Range 20 to 50: 27 Range -6 to 15: -2
No comments:
Post a Comment