-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntax.cpp
29 lines (22 loc) · 1.07 KB
/
syntax.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//................................................................................................................................
//random number
Function prototype: int rand (void);
Parameters: none
Return value: An integer value between 0 and RAND_MAX.
Description: The rand () function generates the next random number in the sequence.
The number generated is the pseudo-random integer between 0 and RAND_MAX. RAND_MAX is a constant in the header <cstdlib> generally set to value 32767.
//see how to print random number
for (int count=1; count <= 100; ++count)
{
cout << rand() << "\t";
// display 5 random numbers per row
if (count % 5 == 0)
cout << "\n";
}
//C++ program given below displays the first five random numbers between 0 and 1.
cout<<"Random numbers generated between 0 and 1:"<<endl;
for (int i = 0; i < 5; i++)
{
cout << (float) rand()/RAND_MAX << endl;
}
//........................................................................................................................................