C program to generate random numbers in any range

Here is a C program to generate random numbers between any range of two digit numbers –

#include  
#include 
main(){
         int s, a, b, n, ran;

         srand(time(0)); // this is to set the seed to current time so we get different random numbers in each try         

         printf("\nEnter lower limit>>");

         scanf("%d",&a);
         printf("\nEnter upper limit>>");

         scanf("%d",&b);

         printf("\nEnter how many random numbers you need");
         scanf("%d",&n);
         
         for (s = 1; s <= n; s++) { 
            ran = (rand() % (b - (a + 1))) + a; 
            printf("\nRandom #i>> %d ", num); 
         }          
}

Add a Comment

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