finding factors

#include <stdio.h>

int main()
{
int number;
int sum = 0;
int product = 1;
int factor;
int counter = 0;

printf("Enter an integer greater than 1\n");
scanf("%d", &number);

while (number <=1) {
printf("\n");
printf("%d is an invalid number. ", number);
printf("Please re-enter a number greater than 1. \n");
scanf("%d", &number);
}
if (number % counter == 0)
{
printf("%d", counter);
sum = sum + counter;
product = product * counter;
counter++;
}


printf("The number of positive factors of %d is %d.\n", number, counter);
printf("The sum of the positive factors of %d is %d.\n", number, sum);
printf("The product of the positive factors of %d is %d.\n", number, product);


printf("\n\n");
system("PAUSE");
return 0;
}


so this is what i have so far, i have the error checking portion of the problem correct but i can't find my factors.

i know how to get the sum and product but i need to get the factors before that, can anyone guide me in the right direction???

i have to be able to get the factors and list them so for example....

the positive factors of 9 are
1 3 9


You could use a simple for-loop and the '%' operator: if a is a factor of b, b%a should be 0.
Topic archived. No new replies allowed.