我在学习纽约大学的一个例子,我以前从来没有和C做过任何事情,所以我可能不知道我在做什么。
考虑下面的程序。
我需要用emacs编写的C代码的shebang行吗?
当我使用gcc -g -o forwardadding forwardadding.c
我听到了这样的信息:

forwardadding.c:9:17: error: expected expression before ‘<’ token

一旦我得到代码编译,我就可以使用gdb调试并运行代码correct?
代码:
#include <stdio.h>
#include <math.h>

main()
{
    float sum, term;
    int i;
    sum = 0.0;
    for( i = 1; < 10000000; i++)
    {
        term = (float) i;
        term = term * term;
        term = 1 / term;
        sum += term;
    }
    printf("The sum is %.12f\n", sum);
}

最佳答案

您需要在for循环中为完整表达式(可能是第9行…)添加一个变量

for( i = 1; < 10000000; i++)

改成这个
for( i = 1; i < 10000000; i++)

关于c - 使用gcc编译C程序,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16503983/

10-12 16:10
查看更多