tags:

views:

55

answers:

1
  void main()
 {

  randomize();
  char city[][10]={"DEL","CHN","KOL","BOM","BNG"};
  int i,fly;
  for(i=0;i<3;i++)
  {
   fly=random(2)+1;
   cout<<city[fly]<<":";
  }
 }

What is the output of the following code snippet?

+3  A: 

If you want the same output every time you run a program using random number generators, you want to seed the generator with the same value every time. For example:

#include <cstdlib>
#include <iostream>
using namespace std:

int main() {
   srand( 42 );  // generator always seeded with same value
   for ( int i = 0; i < 10; i++ ) {
      cout << rand() << endl;
   }
}

always produces the same sequence.

anon
please tell me the possible outputs of my code
anurag18294