You are here

C++ program to generate random numbers

C++ program to print random numbers.

C++ programming code

  1. #include<iostream>
  2. #include<cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. main()
  7. {
  8.    int n, max, num, c;
  9.  
  10.    cout << "Enter the number of random numbers you want ";
  11.    cin >> n;
  12.    cout << "Enter the maximum value of random number ";
  13.    cin >> max;  
  14.      
  15.    cout << "Random numbers from 0 to " << max << " are:" << endl;
  16.      
  17.    for ( c = 1 ; c <= n ; c++ )
  18.    {
  19.       num = random(max);
  20.       cout << num << endl;
  21.    }        
  22.    
  23.    return 0;
  24. }