Code: C

#include <iostream>

#include <vector>

#include<conio.h>

using namespace std;

int main( )

{

const int DIFFERENT_NUMBERS = 10;

// Prompt for and read number of games.

int totalNumbers;

cout << "How many numbers to generate?: ";

cin >> totalNumbers;

// Initialize the vector to zeros.

vector <int> numbers( DIFFERENT_NUMBERS + 1,0 ) ; // shorthand for the following code

/* for( int i = 0; i < numbers.size( ) ; i++ )

numbers[ i ] = 0; */

// Generate the numbers.

for( int j = 0; j < totalNumbers; j++ )

numbers[ rand( ) % DIFFERENT_NUMBERS + 1 ]++ ;

// Output the summary.

for( int k = 1; k <= DIFFERENT_NUMBERS; k++ )

cout << k << " occurs " << numbers[ k ]<< " time(s) \n";

getch();

}

hello ,

I am having trouble understanding the program from (generate the numbers).

please explain it dissecting the code from there !

thnx

*Last edited by SaswatPadhi; 21Jun2009 at 17:58.. Reason: Code blocks*