‘C’ program to calculate the sum of factors of a number.

C File =>


/* Write a ‘C’ program to calculate the sum of  factors of a number. */

#include <stdio.h>
int main() 
{
        int n, i,fact[100],sum=0;
 
        printf("\n Enter a positive integer: ");
        scanf("%d",&n);
        printf("\n Factors of %d are: ", n);

        for (i = 1; i < n; ++i) 
       {
             if (n % i == 0) 
            {
                   printf("%d\t", i);
                   sum=sum+i;
             }
         }
        printf("\n Sum of factors : %d",sum);
 return 0;
}

Comments

Popular posts from this blog

Write a program to allocate memory dynamically for n integers. Accept the elements and calculate their sum and average

C program to accept names of n cities and search for city named “Pune”.