Created
December 10, 2018 18:22
-
-
Save LarryRuane/f88d0f2a060ce6da9a9267590d541fc8 to your computer and use it in GitHub Desktop.
count the number of times "5" appears when counting from 1 to 1000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let mut c = 0; | |
for i in 1..=1000 { | |
let mut j = i; | |
while j > 0 { | |
if j % 10 == 5 { | |
c += 1; | |
} | |
j /= 10; | |
} | |
} | |
println!("{}", c); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment