FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 54   



Following program shows you how to take a max limit from user and generate a random number till that number.
In this program we get max limit number from user and generate a random number using rand()

#include <stdio.h>
int main(void) {
    int maxLimit;
    int lower = 0;
    printf("Enter maxlimit to generate a random number: ");
    scanf("%d", &maxLimit);
    int result = (rand() + lower) % (maxLimit + 1);
    printf("Random number is: %d ", result);
}

Output:

Example1:

Enter maxlimit to generate a random number:  50
Random number is: 10

Example2:

Enter maxlimit to generate a random number:  1000
Random number is: 897



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News