Integer Division and Remainders
Well done! Let's consider the integer division. This kind of division, to be honest, is used almost every day, and you may not notice it.
For example, if you have 16 candies and want to share them among your three friends equally. Then, each friend will receive five candies, and there will be one remaining candy (since 16 = 5*3 + 1). In math, we call that the result of integer division of 16
by 3
is 5
, and 1
is the remainder of this division.
In R, you can perform these operations by using:
%/%
- integer division.%%
- the remainder of a division.
The example above can be calculated using R by the following syntax:
1234# Number of candies for each friend 16 %/% 3 # Number of candies remaining 16 %% 3
The output is:
[1] 5
[1] 1
Swipe to start coding
Using integer division and remainder, complete the following tasks:
- Calculate the number of whole days in
435
hours. - Calculate the number of the remaining hours.
Remember, one day consists of 24 hours.
Løsning
Takk for tilbakemeldingene dine!
single
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Awesome!
Completion rate improved to 12.5
Integer Division and Remainders
Sveip for å vise menyen
Well done! Let's consider the integer division. This kind of division, to be honest, is used almost every day, and you may not notice it.
For example, if you have 16 candies and want to share them among your three friends equally. Then, each friend will receive five candies, and there will be one remaining candy (since 16 = 5*3 + 1). In math, we call that the result of integer division of 16
by 3
is 5
, and 1
is the remainder of this division.
In R, you can perform these operations by using:
%/%
- integer division.%%
- the remainder of a division.
The example above can be calculated using R by the following syntax:
1234# Number of candies for each friend 16 %/% 3 # Number of candies remaining 16 %% 3
The output is:
[1] 5
[1] 1
Swipe to start coding
Using integer division and remainder, complete the following tasks:
- Calculate the number of whole days in
435
hours. - Calculate the number of the remaining hours.
Remember, one day consists of 24 hours.
Løsning
Takk for tilbakemeldingene dine!
Awesome!
Completion rate improved to 12.5single