Rand_max

This is a discussion on Rand_max within the C Programming forums, part of the General Programming Boards category; I am trying to write a program that would print the value of RAND_MAX here is the code Code: #include ...

  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,185
    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,185
    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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21