Create 10 different Random numbers

Below is the program in C language that will create and display 10 different random numbers.
This program will make use of srand function in C.

In order to generate random numbers, srand is usually initialized to some distinctive value. We will also make use of time function as time function will return different value at different time. The value returned by the time function will act as a parameter to srand function.

Here is the code…

#include
#include
#include
void main()
{
    int i;
    clrscr();
    srand( (unsigned)time( NULL ) );
    
    for (i=0; i<10; i++)
    printf("%d ", rand());
    
    printf("\n");
    getch();
}

You may also like...

2 Responses

  1. great use of rand function
    Thanks

  2. Reshma K C says:

    can anyone plz post the ans for same qstn using pointers?????

Leave a Reply

Your email address will not be published. Required fields are marked *

FREE C Cheatsheet - Speed Up Your C Programming.

FREE C Cheatsheet - Speed Up Your C Programming.

Download a 7-page free cheat sheet for easy and quick access to C Concepts, Snippets, and Syntax.

Thank you! Check you inbox and access your cheat-sheet