Hello all:
I am writing a program for a course assignment. This is the first time I have been exposed to functions in C. Therefore; I am confused about a few things. But here is my code:
This code cannot compile; it gives an error about trying to convert int* to int when i call the isPrime() function with the &inputNum integer.Code:#include <stdio.h> #include <stdlib.h> int isPrime(int num) { int i,mods; for(i=1;i<=num;i++) { int mod; mod = num % i; if(mod == 0) { mods = mods+1; } } if(mods==2) { return 1; } else { return 0; } } int main(void) { int inputNum; scanf("%d",&inputNum); if(isPrime(&inputNum) == 1) { printf("yes"); } else { printf("no"); } }
Is this something to do with pointers? I do not believe we need to use pointers in this program or... do i?
Also; for functions; can I return true/false inside of 0/1?
Or can I use the function to update a variable in main? For ex: I have a number i got from the user in main; but I want to manipulate it with a function and return it. How can I use a function to do that?
Thanks in advanced!!!