玩转C语言:从1到100的素数挑战
最编程
2024-08-08 21:52:23
...
素数又称质数,有无限个。质数定义为在大于1的自然数中,除了1和它本身以外不再有其他因数的数称为质数。
接下来我们直接上代码:
#define _CRT_SECURE_NO_WARNINGS 10
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<math.h>
int prime(int n)
{
assert(n > 0);
int i = 0;
for (i = 2; i <= sqrt(n); i++)
{
if (n%i == 0)
{
下一篇: 从1到n找出所有的质数 - 用C语言实现