C PROGRAM: Divisors
 Here is a sample Turbo C program that gives the number, sum and product of divisors of a number given by the user. For expert programmers, you may need to do some adjustments if you are using another language apart from C. For those who do not understand programming, just click on the link at the bottom of this page and try the finished program out for yourself. #include #include #include #include #define p printf #define s scanf int ctr,cc,dd,ii,x,n,nmod,z,a[29436],b,k,g; double numdiv,sumdiv,prodiv; char cont; main() { do {  clrscr();    numdiv=1;sumdiv=1;    for (b=0;b<29436;b++) a[b]=0;    p ("Input a number: ");    s ("%d",&n);    x=n;    ctr=2;    do    {   nmod=n%ctr;        if (nmod==0)        {   a[ctr]+=1;            n=n/ctr;            ctr=2;        }    else if (nmod!=0) ctr+=1;    }    while (n!=1);    for (cc=x;cc>0;cc--)        if (a[cc]!=0) numdiv=numdiv*(a[cc]  +1);    p ("\nThe number of divisors is %0.0lf",numdiv);    dd=x-1;    for (dd=x;dd>0;dd--)        if (a[dd]!=0)            sumdiv=sumdiv*(((pow(dd,(a[dd]+1)))-1)/(dd-1));    p ("\nThe sum of the divisors is %0.0lf",sumdiv);    ii=numdiv;    k=ii/2;g=ii%2;    if (g!=0)    {   z=sqrt(x);        prodiv=pow(z,numdiv);        p ("\nThe product of the divisors in numerical form          is %0.0lf",prodiv);        p ("\nThe product of the divisors in exponential           form is %d to the power of %d",z,ii);    }    else    {   prodiv=pow(x,k);        p ("\nThe product of the divisors in numerical form          is %0.0lf",prodiv);        p ("\nThe product of the divisors in exponential          form is %d to the power of %d",x,k);    }    p ("\n\nDo you wish to continue [Y/N]? ");    cont=getche();    } while (cont=='Y'||cont=='y'); }

Home | C PROGRAM: Determining Prime Numbers | C PROGRAM: Prime Factorization | C PROGRAM: Divisors