Compile Error
/in/foo.cc:4:12: error: 'n' was not declared in this scope int factor(n) ^ /in/foo.cc: In function 'int main()': /in/foo.cc:19:21: error: 'factor' cannot be used as a function j = factor(i); ^ /in/foo.cc:24:25: error: 'factor' cannot be used as a function j = factor(k); ^
代码
#include <stdio.h>
#include <math.h>
int factor(n)
{
int i, j = (int)sqrt(n);
if (n % 2 == 0) return 2;
for (i = 3; i <= j; i++)
if (n % i == 0) return i;
return n;
}
int main()
{
int i, j, k, m, n;
scanf("%d%d", &m, &n);
for (i = m; i <= n; i++)
{
j = factor(i);
k = i / j;
printf("%d=%d", i, j);
while (k > 1)
{
j = factor(k);
k /= j;
printf("*%d", j);
}
printf("\n");
}
return 0;
}