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.

40,009 questions

51,956 answers

573 users

How to create a random 5 digits number and get the last 3 digits in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
    srand(time(NULL));

    int number5digits = rand() % 90000 + 10000; // Random number between 10000 and 99999

    // Extract the last 3 digits
    int lastThreeDigits = number5digits % 1000;

    printf("5-digits number: %d\n", number5digits);
    printf("Last 3 digits: %d\n", lastThreeDigits);

    return 0;
}



/*
run:

5-digits number: 82718
Last 3 digits: 718

*/

 



answered Feb 2, 2024 by avibootz

Related questions

1 answer 135 views
135 views asked Dec 10, 2020 by avibootz
2 answers 176 views
1 answer 143 views
2 answers 110 views
2 answers 130 views
...