Saturday 18 November 2017

C++ Program to Use rand and srand Functions


Code:

#include   iostream
#include   stdlib.h
#include   time.h

using namespace std;

int main(int argc, char **argv)
{
    cout << "First number: " << rand() % 100;
    srand(time(NULL));
    cout << "\nRandom number: " << rand() % 100;
    srand(1);
    cout << "\nAgain the first number: " << rand() % 100;
    return 0;
}


Output:

First number: 41
Random number: 98
Again the first number: 41


More C++ Programs:













100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...