Thread: c Programming

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    14

    Smile c Programming

    Hello,
    I was told to create a program which can read numbers from the keyboard, print how many times it occurs and get the most and least number of occurrence printed as well. I've used the getch(), for , define, arrays and switch functions in my program to read numbers from the keyboard and to calculate its occurrance.

    As for the max. and min. number of occurrance, should i define it as well?
    Eg: # define Get_Max 50
    Otherwise, please teach me on how to go about it.

    I read recently from this book, the c programming, they wrote something like this: r=1+rand()%10. What does that mean?

    Thanks.

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by nicoleha
    I read recently from this book, the c programming, they wrote something like this: r=1+rand()%10. What does that mean?
    rand() gets a random number between 0 and RAND_MAX. % is the modulus operator; it returns the remainder left over after integer division. For example, 5 / 2 is 2 with a remainder of 1. So, 5 % 2 is 1. The above snippet returns a random number between 1 and 10.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

Popular pages Recent additions subscribe to a feed