Für Vorlesungen, bitte die Webseite verwenden. https://flavigny.de/lecture
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

25 wiersze
636B

  1. #include "cpp_headers/fcpp.hh"
  2. int main() {
  3. int n = enter_int("Please enter a natural number: ");
  4. // search smallest factor, start with smallest possible: 2
  5. int k=2;
  6. // go until sqrt(n)
  7. while (k <= sqrt(n)) {
  8. // k is factor of n
  9. if (n % k == 0) {
  10. // print out the factor k
  11. print(k);
  12. // reset n to the quotient
  13. n = n / k;
  14. // restart at k=2
  15. k = 2;
  16. } else {
  17. // if k is not a factor, check next one
  18. k++;
  19. }
  20. }
  21. // n is the last prime factor of the original input number
  22. print(n);
  23. }