text: Sum of all proper divisors of a natural number | C ++ program to find sum of all divisors of a natural number ; Function to calculate sum of all proper divisors num -- > given natural number ; Final result of summation of divisors ; there will be no proper divisor ; find all divisors which divides ' num ' ; if ' i ' is divisor of ' num ' ; if both divisors are same then add it only once else add both ; Add 1 to the result as 1 is also a divisor ; Driver program to run the case
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; int divSum ( int num ) { int result = 0 ; if ( num == 1 ) return result ; for ( int i = 2 ; i <= sqrt ( num ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += i ; else result += ( i + num / i ) ; } } return ( result + 1 ) ; } int main ( ) { int num = 36 ; cout << divSum ( num ) ; return 0 ; }