Reputation: 153
I have been getting the follow errors and I'm not sure what to do. I am not sure if I'm not seeing a typo of if it is just wrong. I found this code on a website and was hoping to implement it in a larger program but I am seriously stuck.
test.c: In function ‘main’:
test.c:10:9: error: expected ‘)’ before ‘;’ token
test.c:15:4: error: break statement not within loop or switch
Any help would be greatly appreciated.
#include <stdio.h>
int main()
{
int n, i, count=0;
printf ("Enter a positive number: ");
scanf ("%d", &n);
if (i=2; i<=n/2;i++)
{
if(n%i==0) //line 10
{
count++;
break; //line 15
}
return 0;
}
if (count==0 && n!=1)
printf("%d is a prime number",n);
else
printf("%d is not a prime number",n);
return 0;
1,1 Top
}
Upvotes: 0
Views: 436
Reputation: 8336
if (i=2; i<=n/2;i++)
needs to be a for loop
for (i=2; i<=n/2;i++)
The former is syntactically incorrect.
Upvotes: 3