weixin_35993567 于 2016.09.19 10:20 提问

'main' : undeclared identifier怎么解决

#include
int fun(int n)
{
int a[10000],i,j,count=0;
for(i=2;i<n;i++)
a[i]=1;
i=2;
while (i<n)
{
for (j=a[i]*2;j<=n;j+=a[i])
a[j] = 0;
i++;
while (a[i]==0)
i++;
}
printf("\nThe prime number between 2 to %d\n",n);
for (i=2;i<=n;i++)
if (a[i]!=0)
{ count++;
printf(count%15?"%5d":"\n%5d",a[i]);
return count;
}
main ()
{
int n=20,r;
r=fun(n);
printf("\nThe number of prime is :%d\n",r);

``````    }
``````

}

2个回答

shihengzhen101   2016.09.19 10:36

`````` int fun(int n)
{
int a[10000],i,j,count=0;
for(i=2;i<n;i++)
a[i]=1;

i=2;
while (i<n)
{
for (j=a[i]*2;j<=n;j+=a[i])
a[j] = 0;

i++;
while (a[i]==0)
i++;
}
printf("\nThe prime number between 2 to %d\n",n);
for (i=2;i<=n;i++)
if (a[i]!=0)
{
count++;
printf(count%15?"%5d":"\n%5d",a[i]);
return count;
}
}

int main ()
{
int n=20,r;
r=fun(n);
printf("\nThe number of prime is :%d\n",r);

}

``````
Marksinoberg      2016.09.19 10:27

``````#include <stdio.h>
#include<stdlib.h>
··· ···
``````