C, C++, C#, D, Java, 65 62 bytes
int d(int n){int s=0,i=1;for(;i<=n;++i)s+=n%i>0?0:i;return s;}
This works in all theses 5 programming languages because of similarities.
C, C++ and D optimization : 62 60 bytes
In C++ and D, integers convert implicitly to booleans ( Zero => false, Not Zero => true ), so you don't need to have the !=0
int d(int n){int s=0,i=1;for(;i<=n;++i)s+=n%i?0:i;return s;}
D optimization : golfy template system, 55 bytes
T d(T)(T n){T s,i=1;for(;i<=n;++i)s+=n%i?0:i;return s;}
C++ optimization by c and c-- : 53 52 bytes
int f(int n,int i=0){return++i<n?f(n,i)+i*!(n%i):n;}
Code to test :
C :
printf("%d %d %d %d %d", d(7), d(15), d(20), d(1), d(5));
C++ :
std::cout << d(7) << ' ' << d(15) << ' ' << d(20) << ' ' << d(1) << ' ' << d(5);
C# :
class FindSum
{
int d(int n) { int s = 0, i = 1; for (; i <= n; ++i) s += n % i > 0 ? 0 : i; return s; }
static void Main(string[] args)
{
var f = new FindSum();
Console.WriteLine(string.Format("{0}, {1}, {2}, {3}, {4}", f.d(7), f.d(15), f.d(20), f.d(1), f.d(5)));
}
}
D :
writeln(d(7));
writeln(d(15));
writeln(d(20));
writeln(d(1));
writeln(d(5));
Java :
public class FindSum {
int d(int n){int s=0,i=1;for(;i<=n;++i)s+=n%i>0?0:i;return s;}
public static void main(String[] args) {
FindSum f = new FindSum();
System.out.println(String.format("%d, %d, %d, %d, %d", f.d(7), f.d(15), f.d(20), f.d(1), f.d(5)));
}
}