Pack lunch bags
Integer division counts full groups. The remainder tells you what is left.
Simple example
Start7 ÷ 3
Result2
1
fn main() {
println!("{}", (7 / 3));
println!("{}", (7 % 3));
}
2 1
Advertisements
Everyday examples
You have 17 apples. Each lunch bag holds 5. Show the number of full bags, then the apples left over.
Start17 ÷ 5
Result3
2
fn main() {
let apples: i64 = 17;
let per_bag: i64 = 5;
println!("{}", (apples / per_bag));
println!("{}", (apples % per_bag));
}
3 2