Outputs 20 random numbers from 1 to 100. : Random « Development « C++






Outputs 20 random numbers from 1 to 100.

Outputs 20 random numbers from 1 to 100.
 
#include <stdlib.h>
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
   unsigned int  i, seed;
   cout << "\nPlease type an integer between "
           "0 and 65535: ";
   cin >> seed;     // Reads an integer.
   srand( seed);    
                    
   cout << "\n\n            "
           "RANDOM NUMBERS\n\n";
   for( i = 1 ; i <= 20 ; ++i)
      cout << setw(20) << i << ". random number = " << setw(3) << (rand() % 100 + 1) << endl;
   return 0;
} 

           
         
  








Related examples in the same category

1.Rand functionRand function
2.Random by time