Reputation: 1
Immediately below is the error message I get:
} ^ 1 warning generated. Undefined symbols for architecture x86_64: "_main", referenced from:
implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang:
error: linker command failed with exit code 1 (use -v to see invocation)
And here is the code itself:
#include <stdio.h>
#include <stdlib.h>
int isOddEven (int i) {
for (i=0; i < 100; i++){
if(i % 2 == 0){
printf("%d is an even number\n", i);
return 1;
}
else{
printf("%d is an odd number\n" , i);
return 0;
}
}
}
Upvotes: 0
Views: 610
Reputation: 21
You have not included the main method at all. You have not declared the main method at the top. In c you have to declare the function at the top like a variable first. hence you first have to declare the isOddEven() function at the top.
your code should be something like
#include <stdio.h>
#include <stdlib.h>
void isOddEven();
int main()
{
isOddEven();
return 1;
}
void isOddEven()
{
for (int i = 0; i < 100; i++)
{
if(i % 2 == 0)
{
printf("%d is an even number\n", i);
}
else
{
printf("%d is an odd number\n" , i);
}
}
}
Upvotes: 1
Reputation:
You can try below code:
#include <stdio.h>
int isOddEven (int i) {
if(i % 2 == 0){
return 1;
}
else{
return 0;
}
}
int main()
{
int value = isOddEven(3);
if(value == 1){
printf("Value is even");
}
else{
printf("Value is odd");
}
return 0;
}
Here isOddEven returns a int value which you can check in your main function that value is odd or even.
Upvotes: 0