Our website is made possible by displaying online advertisements to our visitors.Please consider supporting us by disabling your ad blocker.
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu
Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Translate it in your own Language

Print this Job Post

Print Friendly and PDF

Sunday, May 18, 2014

c program to generate random numbers

This c program generates random numbers using random function, randomize function is used to initialize random number generator. If you don't use randomize function then you will get same random numbers each time you run the program.

C programming code using rand

#include <stdio.h>
#include <stdlib.h>
void main() 
{
  int c, n;
  clrscr(); 
  printf("Ten random numbers in [1,100]\n");
  for (c = 1; c <= 10; c++) 
  {
    n = rand()%100 + 1;
    printf("%d\n", n);
  }
  getch();
}

C programming code using random function(Turbo C compiler only)

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
   int n, max, num, c;
   clrscr(); 
   printf("Enter the number of random numbers you want ");
   scanf("%d",&n);
   printf("Enter the maximum value of random number ");
   scanf("%d",&max);
   printf("%d random numbers from 0 to %d are :-\n",n,max);
   randomize();
   for ( c = 1 ; c <= n ; c++ )
   {
      num = random(max);
      printf("%d\n",num);
   }
   getch();
   return 0;
}

No comments:

Post a Comment

Copyright @ CrackMNC 2014-2024
Divas Nikhra Theme by Crack MNC