fork download
  1. #include <stdio.h>
  2.  
  3. void factor(int n, int divisor) {
  4. if (n == 1) return;
  5.  
  6. if (n % divisor == 0) {
  7. printf("%d ", divisor);
  8. factor(n / divisor, divisor);
  9. } else {
  10. factor(n, divisor + 1);
  11. }
  12. }
  13.  
  14. int main() {
  15. int n;
  16. printf("3以上の整数を入力してください: ");
  17. scanf("%d", &n);
  18.  
  19. printf("%d の素因数分解: ", n);
  20. factor(n, 2);
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0s 5312KB
stdin
10
stdout
3以上の整数を入力してください: 10 の素因数分解: 2 5