English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I'm making a simple program that displays the divisors of a number, and also adds the sum of all the divisors (not including the dividend)

Here's my for loop to find the divisors:
for(temp = 1; temp < n; temp++)
{

if(n % temp == 0)
{

cout << temp << endl;

}

}

My question is, how can I find the total of all the quotients? I know I need to have one more variable, but it's been awhile since I've programmed. Any tips? Thanks.

2007-01-26 02:37:03 · 1 answers · asked by Defcon6 2 in Computers & Internet Programming & Design

1 answers

int sum=0;
for(temp = 1; temp < n; temp++)
{

if(n % temp == 0)
{

sum=sum+(n /temp);
cout << temp << endl;

}
cout << sum << endl;
}

2007-01-26 02:51:24 · answer #1 · answered by iyiogrenci 6 · 2 0

fedest.com, questions and answers