fork download
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int n;
  6. int count = 0;
  7. int sum = 0;
  8. int i;
  9.  
  10. printf("整数を入力してください:");
  11. scanf("%d", &n);
  12.  
  13.  
  14. // 約数を探す
  15. for(i = 1; i <= n; i++) {
  16.  
  17. if(n % i == 0) {
  18. count++; // 約数の個数
  19. sum += i; // 約数の合計
  20. }
  21. }
  22.  
  23.  
  24. printf("約数の個数:%d\n", count);
  25. printf("約数の和:%d\n", sum);
  26.  
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5316KB
stdin
Standard input is empty
stdout
整数を入力してください:約数の個数:6
約数の和:57344