+ 1

How will this function work?

int main () { for (int x = 1; x <= 10; x++) { cout << 1 + (rand() % 6) << endl; } } /* Output: 6 6 5 5 6 5 1 1 5 3 */

24th Jul 2020, 12:43 PM
Muthukkumar
3 Answers
+ 2
rand() is build in function and that %6 mean that it will take random number from 0 to 5 not included number 6 and then it will add 1 to it each time.It will execute till the condition is fully executed
24th Jul 2020, 12:48 PM
Abdulaziz Abdurasul
Abdulaziz Abdurasul - avatar
0
Muthukkumar If it is c++ question, what's the use of Python tag here
24th Jul 2020, 1:30 PM
David