I have typed out a simple program counting the number of positive divisors of a number in C, which works in CodeBlocks GCC compiler but not in the online compiler provided by the school, where it prints out some numbers close to 22k (22019 21873) etc after some inputs.
For example, for input 10 the program prints out 4 which the number of divisors, but in the online compiler it prints out 22019. I noticed when i changed the order of some conditions in the if statements from if (n<0) to if (0>n) the numbers also changed (the 22019 became 22xxx) to numbers different from the first time. Here's the code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int c, n, res = 0;
int i = 1;
scanf("%d", &n);
if (0>n)
printf("Wrong Input");
else {
while (n>=i)
{
res = n%i;
if (res == 0) {
c++;
i++;
}
else {
i++;
}
}
printf("%d", c);
}
return 0;
}