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"); 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. I was able to see I am brain dead and forgot to put a &
in the scanf()
. So scanf("%d",number) --> scanf("%d",&number)
. If someone could tell me how to make him the top answer would appreciate!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.