This is my code which is supposed to output prime numbers only.
#include <stdio.h>
int prime(int n){
int j;
for (j=2;j<=n/2;j++){
if((n%j)==0){
return 0;
}
else{
return 1;
}
}
}
void main(){
int i,p;
for (i=2;i<=100;i++){
p=prime(i);
if(p==1){
printf("%d \n",i);
}
}
}
The result is 2,3,7,9,11,13,15....
not 2,3,5,7,11,13....
What did I do wrong?