Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasw-mitutoyo-ctl/79ece0ba0264cb39c437984a0b63202b to your computer and use it in GitHub Desktop.
Save thomasw-mitutoyo-ctl/79ece0ba0264cb39c437984a0b63202b to your computer and use it in GitHub Desktop.
Zahlen mit Ziffer 3 von vorne
import "dart:math" as math;
void main() {
var anzahlZahlenMitDrei = 0;
for (var i = 100; i <= 999; i++) {
for (int stelle = 6; stelle > 0; stelle--) {
var wertigkeit = math.pow(10, stelle).toInt(); // 10^stelle
var hintenAbgeschnitten = i ~/ (wertigkeit ~/ 10);
var vorneAbgeschnitten = hintenAbgeschnitten % 10;
if (vorneAbgeschnitten == 3) {
anzahlZahlenMitDrei++;
break; // for-Schleife beenden
}
}
}
print("Anzahl Zahlen mit 3: ${anzahlZahlenMitDrei}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment