You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
356 B

函数———判断素数
一、目的
通过编写代码来判断一个数字是否为素数。
二、代码
#include<stdio.h>
int main()
{
int a=0;
int num;
scanf("%d",&num);
for(int i=2;i<num;i++)
{
if(num%i==0)
a++;
}
if(a==0)
{
printf("%d是素数",num);
}
else
printf("%d不是素数",num);
return 0;
}