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:
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 advanceCode:#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); }



LinkBack URL
About LinkBacks



Knowing what each piece does isn't the same as understanding how they work together as a whole. The former is easy, the latter takes a bit of staring even for simple programs.