Just started C programming, and I'm trying to make this little code. I'm guessing you guys know what its point is since ur all expererts:
Code:
#include <stdio.h>
int main(void)
{
int input, x, count;
printf("Enter a positive integer: ");
scanf("%d", &input);
printf("The factors of %d are: \n", input);
for (x = 1, count = 0; x <= input; x++)
{if (input % x == 0)
printf("%d is a factor of %d\n", x, input);
count++;
}
printf("# of factors is %d\n", count);
}
The problem is when I run this the "count" vcariable always equals "input". Why is it so, I mean I did the if statement so that the count increases only if input % x == 0. A bit confusing . Thanks in advance