Numbers


  1. What is the default operation of adjacent_difference function in numeric library?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The default operation is to calculate the difference, but some other operation can be specified as binary operator instead.


  1. Which operator is used to produce a certain number in a specific range?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    In C++, modulo operator is denoted by %.



  1. What is the output of this program?
    #include <iostream>
    #include <ctime>
    #include <cstdlib>
    using namespace std;
    int main()
    {
    srand((unsigned)time(0));
    int ran;
    int L = 11, H = 100;
    int R = (H - L) + 1;
    for(int k = 0; k < 1; k++)
    {
    ran = L + int(R * rand() / (RAND_MAX + 1.0));
    cout << ran << endl;
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    In this program, We have generated a certain random number by using the above formula.


  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. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

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



  1. What is the output of this program?
     #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    int main ()
    {
    srand (time(NULL));
    printf ("Random number is: %d\n", rand() % 50);
    srand (1);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    This program will create a random number based on time function using srand function.