-3

我试图找到从 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 个

4

1 回答 1

3
float l  

这里少了分号

printf(n, l);

这不是如何printf使用的,而是使用它:

printf("%f, %f", n, l);

这应该可以解决编译问题。

于 2013-08-24T03:26:45.220 回答