how to jump from the if state 5th tiime without printing else.?
int n=16;
for(i=0;1<=n;i++) { if(n/i==i) { printf("its a prime no");
} else printf("not a prime no.");
i wanto print one statement niethe开发者_StackOverflow社区r else statement nor if statement.... but output getting not a prime 3time and prime no one time againg...
help me
A few errors:
n/i==i
is wrong.
i
divides n
(aka i
is a factor of n
) if n % i == 0
(remainder is zero)
i=0;1<=n;i++
n/i==i
will cause division by zero because initially i
is zero,
plus having 1<n
in the for
, the loop will not terminate. It should be i<n
.
Not sure if this is what you're looking for.
int n = 16;
for(i=2;i<n;i++)
{
if(n % i == 0)
{
printf("Not a prime no.");
break;
}
else
{
continue;
}
}
if (i == n)
{
printf("A prime no.");
}
精彩评论