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,895 questions

51,826 answers

573 users

How to generate 8 digits int random number in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <time.h> 
 
int generate_8_digits_random_number() {
    return rand() % 90000000 + 10000000; // numbers from 10000000 to 99999999
}
 
int main() {
    srand(time(NULL)); 
 
    for (int i = 0; i < 10; i++) {
        printf("%d\n", generate_8_digits_random_number()); 
    }
 
    return 0;
}
 
 
   
   
/*
run:
   
44576519
65418862
52962244
89032537
90614137
23762527
80816249
31175098
58783260
67654028
   
*/

 

 



answered May 13, 2024 by avibootz
edited May 13, 2024 by avibootz

Related questions

1 answer 131 views
1 answer 130 views
1 answer 86 views
1 answer 88 views
1 answer 89 views
1 answer 96 views
...