언어/c언어
소수 판별 코드
파아랑새
2017. 8. 26. 10:41
# include <stdio.h>
# include <math.h>
int main(void)
{
int count;
for (int i = 2; i < 10; i++)
{
count = 0;
if (i == 2)
{
printf("%d \n", i);
}
else // i!= 2
{
for (int j = 1; j <= (int)sqrt(i); j++)
{
if (i%j == 0)
{
count++;
}
}
if (count == 1)
{
printf("%d \n", i);
}
}
}
return 0;
}