Skip to content

Instantly share code, notes, and snippets.

@LarryRuane
Created December 10, 2018 18:22
Show Gist options
  • Save LarryRuane/f88d0f2a060ce6da9a9267590d541fc8 to your computer and use it in GitHub Desktop.
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
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