我试图找到从1到100的每个数字的除数的数量,但我不明白为什么它不起作用。编译器说错误在第18,21和24行。
#include <stdio.h>
#include <math.h>
#define N 100
int main()
{
float n;
float l
for (n=1; n<=N; n++) { //genertate a list of numbers
int a;
for (a=n; a>=n; a--) { //genarate a list of numbers less than "n"
l = n/a; //divide each number less than "n"
if (l == round(l)) { //see is "l" is a divisor of "n"
l=l+1; //if it finds a divisor it will add it
printf(n, l); //prints the number as well as the number of divisors
}
}
}
}
以下是编译器发出的警告:
ks-MacBook-Pro:~ kyle$ gcc /Users/kyle/app-tests/c/divisors.c
/Users/kyle/app-tests/c/divisors.c: In function 'main':
/Users/kyle/app-tests/c/divisors.c:18: error: nested functions are disabled, use -fnested-functions to re-enable
/Users/kyle/app-tests/c/divisors.c:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'for'
/Users/kyle/app-tests/c/divisors.c:21: error: 'l' undeclared (first use in this function)
/Users/kyle/app-tests/c/divisors.c:21: error: (Each undeclared identifier is reported only once
/Users/kyle/app-tests/c/divisors.c:21:错误:对于它出现的每个函数。) /Users/kyle/app-tests/c/divisors.c:24:错误:'printf'的参数1的不兼容类型
答案 0 :(得分:3)
float l
在这里缺少分号
printf(n, l);
这不是printf
的使用方式,而是使用它:
printf("%f, %f", n, l);
这应解决编译问题。