The sum subprogram has a single parameter, n, through which it receives a natural number (nī [1,106]). The subroutine returns the sum of the positive divisors of n that are not prime. Write the complete definition of the subroutine. Example: for n = 12 the subroutine returns 23 (23 = 1 + 4 + 6 + 12).
This is what i've tried, but no results..
int suma(int n)
{
int d,s=0,prim;
prim=1;
if(n<2)
{
prim=0;
s=n;
}
for(d=2; d*d<=n; d++)
{
if(n%d==0)
prim=0;
if(prim==0)
s+=d;
}
return s;
}