140k views
1 vote
LANGUAGE: C++

CHALLENGE:
Write the necessary preprocessor directive to enable the use of the rand function.

User Qu
by
8.4k points

1 Answer

4 votes

Answer: To enable the use of the rand function in C++, you need to include the <cstdlib> header file. This header file contains the declaration of the rand function, as well as other functions and constants related to random number generation.

Here's the preprocessor directive you can use to include the <cstdlib> header file:

cpp

Copy code

#include <cstdlib>

Once you've included this header file, you can use the rand function to generate random numbers in your program. Remember that you'll also need to call srand to seed the random number generator before using rand.

Step-by-step explanation:

User Damson
by
7.4k points