素數是指在大於1的自然數中,除了1和它本身以外不再有其他因數的自然數,也稱質數。
#include <stdio.h>
int main()
{
int a,b,c=0;
printf("Please input a number\n");
scanf("%d",&a);
for(b=2;b<a;b++)
{
if(a%b==0)
{
c++;
}
}
if(c==0)
{
printf("你輸入的是一個素數");
}
else
printf("你輸入的不是一個素數");
return 0;
}
【運行結果】