简体   繁体   English

我的代码计算两个数字的总和和平均值,在执行和编译时返回此错误“[Error] ld returned 1 exit status”

[英]My code which is calculating sum and average of two numbers returns this error "[Error] ld returned 1 exit status" upon execution and compilation

This is my code.这是我的代码。 I've read the output log but can't see where the exact error is;我已经阅读了 output 日志,但看不到确切的错误在哪里; I will appreciate if someone can kindly point me to it.如果有人能指点我,我将不胜感激。 The IDE I'm using is Dev C++.我正在使用的 IDE 是 Dev C++。

int main(){
    int n, i, a, average, sum;
    printf("enter the number of integers to be picked\n");
    scanf("%d", n);
    
    sum=0;
    printf("Enter a number.");
    scanf("%d", &a);
    
    for (i=0; i<=n;i++){
        printf("%d", i);
        sum=sum + a;
    }
    average=sum/n;
    printf("The average is %d", average);
    return 0;
}

You're just missing the & (address-of operator) in line 4 ( scanf("%d",&n); ).您只是缺少第 4 行( scanf("%d",&n); )中的& (地址运算符)。 Putting this operator will tell the compiler, the address of n , where the value of n will be kept.放置此运算符将告诉编译器n的地址, n的值将保存在哪里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM