C语言关于函数声明的问题,为什么声明后还是报错说函数未定义
#include<stdio.h>voidsushu(intn);intmain(void){unsignedlongnum;unsignedlongdiv,a,b;pr...
#include<stdio.h>
void sushu(int n);
int main(void)
{
unsigned long num;
unsigned long div,a,b;
printf("Please enter an integer for analysis,number bigger 2");
printf("Enter q to quit.\n");
while( (scanf("%lu",&num))==1)
{
if((num==1)||(num==2))
printf("1 he 2 dou shi su shu \n");
else
{
for(a=2;a<=num;a++)
{
sushu(a);
}
}
}
void sushu(int n)
{
int a,b=0;
for(a=2;a<n;a++)
{
if(n%a==0)
{
b++;
break;
}
}
if(b==0)
printf(" %d ",n);
}}
做书里的一个练习题,我在前面声明了函数sushu为什么会报错呢,报错信息是/tmp/ccqJzeC7.o: In function `main':
/home/hy/c/xt7/9.c:20: undefined reference to `sushu'
请高人指点一下,我将函数提前main之前就可以正常编译运行,为什么声明后还是不行呢 展开
void sushu(int n);
int main(void)
{
unsigned long num;
unsigned long div,a,b;
printf("Please enter an integer for analysis,number bigger 2");
printf("Enter q to quit.\n");
while( (scanf("%lu",&num))==1)
{
if((num==1)||(num==2))
printf("1 he 2 dou shi su shu \n");
else
{
for(a=2;a<=num;a++)
{
sushu(a);
}
}
}
void sushu(int n)
{
int a,b=0;
for(a=2;a<n;a++)
{
if(n%a==0)
{
b++;
break;
}
}
if(b==0)
printf(" %d ",n);
}}
做书里的一个练习题,我在前面声明了函数sushu为什么会报错呢,报错信息是/tmp/ccqJzeC7.o: In function `main':
/home/hy/c/xt7/9.c:20: undefined reference to `sushu'
请高人指点一下,我将函数提前main之前就可以正常编译运行,为什么声明后还是不行呢 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询