93c16edb5a
- 修正主README.md中的所有路径引用,使其与当前文件结构一致 - 更新翁凯C语言学习指南链接路径 - 更新五子棋AI项目文档链接路径 - 更新数据结构学习文档链接路径 - 修正编译说明和学习模块使用指南中的目录路径 - 改进五子棋README.md的编译运行说明,增加Windows和Linux/macOS的分平台指导 - 确保所有文档链接和路径引用都能正确工作
49 lines
519 B
C
49 lines
519 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <time.h>
|
|
#include <math.h>
|
|
|
|
// !素数判断的简化版本
|
|
int sushu(int x)
|
|
{
|
|
int ret = 1;
|
|
|
|
if (x <= 1)
|
|
{
|
|
ret = 0;
|
|
}
|
|
|
|
int i;
|
|
if (x == 2 || (x % 2 == 0 && x != 2)) // 排除偶数
|
|
{
|
|
ret = 0;
|
|
}
|
|
for (i = 3; i < (int)sqrt(x)+1; i += 2)
|
|
{
|
|
if (x % i == 0)
|
|
{
|
|
ret = 0;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
int x;
|
|
printf("输入数字:");
|
|
scanf("%d", &x);
|
|
|
|
if (sushu(x))
|
|
{
|
|
printf("%d是素数\n", x);
|
|
}
|
|
else
|
|
{
|
|
printf("%d不是素数\n", x);
|
|
}
|
|
|
|
return 0;
|
|
} |