Pages

Tuesday, March 25, 2014

C++ Program to generate random numbers of certain maximum value

//to genetare random numbers
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
   int n, max, num, c;
   cout << "Enter the number of random numbers you want ";
   cin >> n;
   cout << "Enter the maximum value of random number ";
   cin >> max;  
   cout << "random numbers from 0 to " << max << " are :-" << endl;
   for ( c = 1 ; c <= n ; c++ )
   {
      num = rand( );
      num%=max;
      cout << num << endl;
   }
   system("pause");        
   return 0;
}

No comments:

Post a Comment