This blog is under construction

Monday, 30 April 2012

rand example in C

Header file:
    stdlib.h

Synopsis:
     int rand(void);

Description:
     It returns a pseudo random integer value.


rand function C example


  #include<stdio.h>
  #include<stdlib.h>
  int main() {
        int randomno, i, n;
        printf("Enter the no of random numbers you want to generate:");
        scanf("%d", &n);

        for(i = 1; i < n; i++)
                printf("Random no %d: %d\n", i, rand());
        return 0;
  }



  Output:
  jp@jp-VirtualBox:~/$ ./a.out
  Enter the no of random numbers you want to generate:4
  Random no 1: 1804289383
  Random no 2: 846930886
  Random no 3: 1681692777




No comments:

Post a Comment