# Sum of factors in a loop

Page 1 of 1

## 2 Replies - 11746 Views - Last Post: 13 February 2008 - 10:03 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=43200&amp;s=74d9fc28211c12ff5f258e516579a6ab&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 salyard

Reputation: 0
• Posts: 2
• Joined: 12-February 08

# Sum of factors in a loop

Posted 13 February 2008 - 09:57 AM

I have a code where I am making factors of a number but I am unable to figure out how to put the sum of factors in my loop so far I have this
```#include <stdio.h>
#include<stdlib.h>
int main (void){
int i,value,factor1,remainder;

printf("Please enter the integer you want to factor.\n");
scanf("%d",&value);

for (i=1; i*i<=value; i++)
{

remainder = value % i;
if (remainder == 0)
{
factor1 = i;
/*factor2 = value / i;*/
printf("FACTOR = %d\n",factor1);
/*printf("FACTOR 2 = %d\n", factor2);
if (factor1>factor2)
break;*/
}

}

system("pause");

return 0;

}
```

Is This A Good Question/Topic? 0

## Replies To: Sum of factors in a loop

### #2 letthecolorsrumble

• Student of The Sun

Reputation: 27
• Posts: 555
• Joined: 07-November 07

## Re: Sum of factors in a loop

Posted 13 February 2008 - 10:13 AM

salyard, on 13 Feb, 2008 - 09:57 AM, said:

I have a code where I am making factors of a number but I am unable to figure out how to put the sum of factors in my loop so far I have this

```#include <stdio.h>
#include <stdlib.h>

int main (){

int i,value,factor1,sum=0;

printf("Please enter the integer you want to factor.\n");
scanf("%d",&value);
fflush(stdin);
for (i=1; i<=value; i++){
if (!(value % i)){
factor1 = i;
sum = sum + factor1;
printf("FACTOR = %d\n",factor1);
}
}
printf("Sum of Factors: %d\n\n",sum);
//system("pause");

return 0;

}

```

This should do it for you!

More help?
Keep posting questions!

```#include <stdio.h>
#include <stdlib.h>

int main (){

int i,value,factor1,sum=0;

printf("Please enter the integer you want to factor.\n");
scanf("%d",&value);
fflush(stdin);
for (i=1; i<value; i++){
if (!(value % i)){
factor1 = i;
sum = sum + factor1;
printf("FACTOR = %d\n",factor1);
}
}
printf("Sum of Factors: %d\n\n",sum);
//system("pause");

return 0;

}

```

This is a changed version, which doesn't include the inputted integer as a factor.

This post has been edited by letthecolorsrumble: 13 February 2008 - 10:16 AM

### #3 salyard

Reputation: 0
• Posts: 2
• Joined: 12-February 08

## Re: Sum of factors in a loop

Posted 13 February 2008 - 10:03 PM

Thank you so much! I just needed something like that to remind that I could do it so now I have created it with product of factors and number of factors.