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/f2be1413b7d7b839a8ce1e1df04ea7dd to your computer and use it in GitHub Desktop.
Save thomasw-mitutoyo-ctl/f2be1413b7d7b839a8ce1e1df04ea7dd to your computer and use it in GitHub Desktop.
Zahlen mit der Ziffer 3 (mathematisch von hinten)
void main() {
var anzahlZahlenMitDrei = 0;
for (var i = 100; i <= 999; i++) {
var zahl = i;
while (zahl > 0) {
var letzteZiffer = zahl % 10;
if (letzteZiffer == 3) {
anzahlZahlenMitDrei++;
break; // while-Schleife beenden
}
// Alle Ziffern vor den Einern behalten
// Es verschieben sich Zehner zu Einern, Hunderter zu Zehnern
// Operation ~/ ist Teilen ohne Kommastellen
zahl = zahl ~/ 10;
}
}
print("Anzahl Zahlen mit 3: ${anzahlZahlenMitDrei}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment