Thread: Rand_max

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    18

    Question Rand_max

    I am trying to write a program that would print the value of RAND_MAX here is the code

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    /*
    *                       Main Function
    *
    */
    
            int main(void)
    {
            {
            int i, n;
            for (i = 0; i < n; ++i)
            printf("RAND_MAX = %d\n", RAND_MAX);
            }
    return 0;
    }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Why are you printing it inside a for loop?

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    18

    update

    So I entered the wrong code but here is the updated one. How does it look:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    /*
    *                       Main Function
    *
    */
    
            int main(void)
    {
    
            int i, n;
            printf("Hit the number 1 key and then enter");
            scanf("%d", &n);
            for (i = 0; i < n; ++i)
            printf("RAND_MAX = %d\n", RAND_MAX);
    
    return 0;
    }

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Even sillier. Words cannot express the futility of asking people to enter the number "1". Just print it out and ditch the for loop.

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    18

    ....

    I think with writing these programs I think I have to add in more text for no reason....took out the for loop and the input prompt and still got the same answer....hmmm....thanks!

Popular pages Recent additions subscribe to a feed