返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. main ()
  5. {
  6.         while (true)
  7.     {   
  8.                  int a;
  9.                  int b = 0;
  10.                  int c = 0;
  11.                  float d = 0;
  12.                  
  13.                  cout << "請輸入一個整數:";
  14.                  cin >> a;
  15.                  
  16.                  for (int i = 1; i <= a; i++)
  17.                  {
  18.                          if (a % i == 0)
  19.                          {
  20.                                  cout << i << " ";
  21.                                  b ++;
  22.                                 c = i + c;
  23.                          }
  24.                  }
  25.                  d = c / b;
  26.                  cout << endl;
  27.                  cout << "因數數量:" << b << endl;                  
  28.                  cout << "因數總和:" << c << endl;
  29.                  cout << "因數平均值:" << d <<endl;
  30.                
  31.         system ("pause");
  32.     }
  33.         return 0;
  34. }
複製代碼

TOP

返回列表