Advertisement
SMASIF

Sum of Divisors

Aug 22nd, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.46 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n,sum=0;
  7.     while(cout << "Enter a positive integer: " && cin >> n)
  8.     {
  9.     int i, count=0;
  10.     for(i = 1; i <= n; ++i)
  11.     {
  12.         if(n % i == 0)
  13.         {
  14.             count++;
  15.             cout<<i<<endl;
  16.             sum=sum+i;
  17.  
  18.         }
  19.     }
  20.  
  21.     cout<<"Total number of divisors: "<<count<<endl;
  22.     cout<<"Sum of the divisors: "<<sum<<endl<<endl;
  23.     sum=0;
  24.  
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement