Challenge: Even or Odd
Swipe to start coding
Write a program which checks if the value inside the num variable is even or odd.
A number is even if it is fully divisible by 2. We can easily check this using the remainder operator (%).
For example:
13 % 2gives1which means it's not fully divisible by two, and therefore, it's an odd number.14 % 2gives0, which means it's fully divisible by two, and therefore, it's an even number.
We can use this property to easily distinguish between even and odd numbers.
Write the code to
- Display the text
"The number is even"ifnumis even. - Display the text
The number is odd"ifnumis odd.
For this you'll need to write two different if-statements.
Think about what kind of boolean expression you can write to check if a number is even or odd.
Løsning
Tak for dine kommentarer!
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat
Fantastisk!
Completion rate forbedret til 1.33
Challenge: Even or Odd
Stryg for at vise menuen
Swipe to start coding
Write a program which checks if the value inside the num variable is even or odd.
A number is even if it is fully divisible by 2. We can easily check this using the remainder operator (%).
For example:
13 % 2gives1which means it's not fully divisible by two, and therefore, it's an odd number.14 % 2gives0, which means it's fully divisible by two, and therefore, it's an even number.
We can use this property to easily distinguish between even and odd numbers.
Write the code to
- Display the text
"The number is even"ifnumis even. - Display the text
The number is odd"ifnumis odd.
For this you'll need to write two different if-statements.
Think about what kind of boolean expression you can write to check if a number is even or odd.
Løsning
Tak for dine kommentarer!
single