Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,974 questions

51,918 answers

573 users

How to generate 5 digits random numbers in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h> 
#include <time.h> 
  
int getRandom(int lower, int upper) { 
    return rand() % (upper - lower + 1) + lower; 
} 
  
int main()
{
    srand(time(0)); 
      
    for (int i = 0; i < 15; i++)
        printf("%d\n", getRandom(10000, 99999));
       
    return 0;
}
  
  
  
/*
run:
  
38959
33924
81672
39430
90802
69433
80689
25903
14507
90856
59023
35203
60465
40906
97659
    
*/

 



answered Dec 10, 2020 by avibootz

Related questions

1 answer 127 views
1 answer 84 views
1 answer 91 views
1 answer 90 views
1 answer 78 views
1 answer 110 views
1 answer 92 views
...