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

51,940 answers

573 users

How to generate 3 digits random numbers in C

2 Answers

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 < 20; i++)
        printf("%d\n", getRandom(100, 999));
       
    return 0;
}
  
  
  
/*
run:
  
523
417
930
303
293
276
864
862
219
322
216
748
851
849
582
923
478
182
359
701
    
*/

 



answered Jul 4, 2020 by avibootz
0 votes
#include <stdio.h>
#include <stdlib.h> 
#include <time.h> 
  
int main()
{
    srand(time(NULL)); 

    for (int i = 0; i < 20; i++) {
		printf("%d\n", 100 + (rand() % 900));
	}
       
    return 0;
}
  
  
  
/*
run:
  
754
353
124
808
630
402
428
337
176
180
222
777
572
812
679
943
558
872
286
100
    
*/

 



answered Jul 4, 2020 by avibootz

Related questions

1 answer 129 views
1 answer 125 views
1 answer 160 views
1 answer 104 views
1 answer 134 views
134 views asked Dec 10, 2020 by avibootz
2 answers 227 views
...