C program to generate random numbers using rand function

Generate random numbers using rand function


Write a C program to generate random numbers using rand function. Here’s simple program to generate random numbers using rand function in C Programming Language.


Below is the source code for C program to generate random numbers using rand function which is successfully compiled and run on Windows System to produce desired output as shown below :


SOURCE CODE : :


/*  C program to generate random numbers using rand function  */

#include <stdio.h>
#include <stdlib.h>

int main() {
  int c, n;

  printf("\nTen random numbers in range [1,100] :: \n\n");

  for (c = 1; c <= 10; c++)
 {
    n = rand() % 100 + 1;
    printf(" %d Random Number = %d\n",c,n);
  }

  return 0;
}

OUTPUT : :


/*  C program to generate random numbers using rand function  */


Ten random numbers in range [1,100] ::

 1 Random Number = 42
 2 Random Number = 68
 3 Random Number = 35
 4 Random Number = 1
 5 Random Number = 70
 6 Random Number = 25
 7 Random Number = 79
 8 Random Number = 59
 9 Random Number = 63
 10 Random Number = 65

Process returned 0

Above is the source code for C program to generate random numbers using rand( ) function which is successfully compiled and run on Windows System.The Output of the program is shown above .

If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.


Thanks for reading the post….

Leave a Reply