Q:

C program to generate random numbers using rand function

0

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.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 .

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Number Solved Programs – C Programming

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Write a C program to find nCr and nPr using functi... >>
<< C program to Add two Complex Numbers using structu...