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/e3d80e324549714017110f64f301fcef to your computer and use it in GitHub Desktop.
Save thomasw-mitutoyo-ctl/e3d80e324549714017110f64f301fcef to your computer and use it in GitHub Desktop.
void main() {
var anzahlZahlenMitDrei = 0;
for (var i = 100; i <= 999; i++) {
// Nachteil: muss für jede weitere Stelle zusätzlich programmiert werden, z.B. Tausender
var hunderter = i ~/ 100;
var zehner = (i - hunderter * 100) ~/ 10;
var einer = (i - hunderter * 100 - zehner * 10);
if (hunderter == 3 || zehner == 3 || einer == 3) {
anzahlZahlenMitDrei++;
}
}
print("Anzahl Zahlen mit 3: ${anzahlZahlenMitDrei}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment