Home » C++ Programming » Numbers » Question
  1. What is the output of this program?
     #include <cstdlib>
    #include <ctime>
    #include <iostream>
    using namespace std;
    int main()
    {
    srand((unsigned)time(0));
    int num;
    for (int k = 0; k < 2; k++)
    {
    num = (rand() % 10) + 1;
    cout << num;
    }
    }
    1. 2
    2. 20
    3. 10
    4. Any two number from 1 to 20
    5. Compilation Error
Correct Option: D

In this program, It will produce two numbers from 1 to 20 by using srand function.



Your comments will be displayed only after manual approval.