简体   繁体   English

为什么返回在我的程序中不起作用? C

[英]Why does the return not work in my program? C

So I am a beginner in C and I was trying to use functions in my programs but I cant figure out why my function isn't returning 1 or 0, and if I put a printf("Hello");所以我是 C 的初学者,我试图在我的程序中使用函数,但我无法弄清楚为什么我的函数没有返回 1 或 0,如果我放了一个 printf("Hello"); in the middle of the loop in the function it isn't appearing in the console.在函数的循环中间,它没有出现在控制台中。 Any help would be appreciated!任何帮助,将不胜感激!

int Primo(int x);

int main() {
    Ex4_MED_4();
}

 void Ex4_MED_4(){
    int prime,number;
    printf("Pick a number:");
    scanf("%d",number);
    prime=Primo(number);
    printf("%d",prime);
}

int Primo(int x){
    for(int i=2;i<=x/2;i++){
        if (x%i==0) {
            return 0;
        }
    }
    return 1;
}

I don't know how to mark a comment has a solution, but thanks to @Eugene Sh.我不知道如何标记评论有解决方案,但感谢@Eugene Sh。 I was able to see I am brain dead and forgot to put a & in the scanf() .我能够看到我已经脑死亡并且忘记在scanf()放置一个& So scanf("%d",number) --> scanf("%d",&number) .所以scanf("%d",number) --> scanf("%d",&number) If someone could tell me how to make him the top answer would appreciate!如果有人能告诉我如何让他成为最佳答案,我将不胜感激!

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

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