Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22097

Why is that in c language when changing time in srand(time(0)); to srand(time(1)); does not give output

$
0
0
#include <stdio.h>#include <stdlib.h>#include <time.h>int main() {    int n, m;    printf("Enter the lower bound (n): ");    scanf("%d", &n);    printf("Enter the upper bound (m): ");    scanf("%d", &m);    if (n > m)    {        printf("Invalid range. Ensure that n <= m.\n");        return 1;    }    srand(time(0)); //(here)    int randomInRange = (rand() % (m - n + 1)) + n;    printf("Random number between %d and %d: %d\n", n, m, randomInRange);    return 0;}

when i tried changing the value in srand(time(0)) to srand(time(1))the code runs, takes the user input of n and m but in the end it doesn't give any output. Why is this happening?


Viewing all articles
Browse latest Browse all 22097


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>