/* C Program to find the sum of factors of a given number */
#include <stdio.h>
int main()
{
int sum=0;
int ctr;
int num;
printf("Enter the number\n");
scanf("%d",&num);
if(num==1)
{
sum=1;
}
for(ctr=2;ctr<=num;ctr++)
{
if((num%ctr)==0)
{
num=num/ctr;
sum=sum+ctr;
ctr=1;
}
if(num==1)
{
break;
}
}
printf("The sum of the factors is %d",sum);
return 0;
}
No comments:
Post a Comment