Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Why does this code produce the number 1?

Panasonic99Panasonic99 Member Posts: 140
#include
#include
#include

Comments

  • pseudocoderpseudocoder Member Posts: 701 ✭✭✭
    a number % 1 will return 0 since there is no remainder; you're getting the same results every time the program executes

    n1 = rand() % 1 + 21 or n1 = 21
    n2 = rand() % 1 + 10 or n2 = 10

    21 % 10 has a remainder of 1
    [code]
    2
    -----
    10 | 21
    - 20
    ---
    1
    [/code]
    : #include
    : #include
    : #include
Sign In or Register to comment.