- #include<iostream>
- #include<cstdlib>
- using namespace std;
- main ()
- {
- while (true)
- {
- int a;
- int b = 0;
- int c = 0;
- float d = 0;
-
- cout << "請輸入一個整數:";
- cin >> a;
-
- for (int i = 1; i <= a; i++)
- {
- if (a % i == 0)
- {
- cout << i << " ";
- b ++;
- c = i + c;
- }
- }
- d = c / b;
- cout << endl;
- cout << "因數數量:" << b << endl;
- cout << "因數總和:" << c << endl;
- cout << "因數平均值:" << d <<endl;
-
- system ("pause");
- }
- return 0;
- }
複製代碼 |