Write a program to find the sum of all the divisors of n.
Example:
Input: n = 30
Output: 42
Approach
C++
#include <bits/stdc++.h>using namespace std;int main(){int n = 30;int res = 0;for (int i = 1; i < n; i++){if (n % i == 0){res += i;}}cout << res << "\n";return 0;}
No comments:
Post a Comment