‘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
Post a Comment
Please do not enter any spam link in message.