#include // The sigma_1(n) function returns the sum of the // positive divisors of a positive integer 'n'. // // For example, the positive divisors of 12 are // // 1, 2, 3, 4, 6, 12, // // so // // sigma_1(12) = 1 + 2 + 3 + 4 + 6 + 12 = 28. // // For a prime number 'p', the only positive divisors // are 1 and p, and therefore // // sigma_1(p) = 1 + p. // // Write a function that calculates the sum of the // positive divisors of 'n'. // // If n <= 0, return 0. // Function declarations int main(); int sigma1( int n ); // Function definitions int main() { for ( int m{ 0 }; m <= 50; ++m ) { std::cout << "sigma1(" << m << ") = " << sigma1( m ) << std::endl; } return 0; } int sigma1( int n ) { return 0; } // Hint: // Iterate through all the integers 'k' from 1 through n. // If n%k == 0, then 'k' is a divisor of 'n', so add 'k' // to the sum. // Here is one solution: /* int sigma1( int n ) { if ( n <= 0 ) { return 0; } int sum{ 0 }; for ( int k{ 1 }; k <= n; ++k ) { if ( n%k == 0 ) { sum += k; } } return sum; } */