#include<stdio.h>
int isprime( int x, int knownprime[], int numberofknownprime);
int main()
{
const int number = 10;
int prime[number] = {2};
int count = 1;
int i = 3;
while ( count < number )
{
if( isprime( i, prime, number))
{
prime[count++] = i;
}
i++;
}
for (int i = 0; i < number; i++)
{
printf("%d",prime[i]);
if (i+1%5) printf("\t");
else printf("\n");
}
return 0;
}
int isprime( int x, int knownprime[], int numberofknownprime)
{
int ret = 1;
for ( int i = 0; i < numberofknownprime; i++)
{
if( x % knownprime[i] == 0)
{
ret = 0;
break;
}
}
return ret;
}
我是在教学视频中学习有关C语言函数和数组的学习里进行上述代码的编译,想要实现的是素数的求解,输出前十个素数吧,求解:为什么我这里已经定义了常量,还是给出错误提示:可变的数组不能初始化