Chinaunix首页 | 论坛 | 博客
  • 博客访问: 309464
  • 博文数量: 72
  • 博客积分: 3111
  • 博客等级: 中校
  • 技术积分: 668
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-30 15:45
个人简介

朝着心的方向前进

文章分类

全部博文(72)

文章存档

2014年(5)

2013年(1)

2012年(1)

2011年(1)

2010年(24)

2009年(40)

我的朋友

分类: LINUX

2010-10-28 17:16:41

本例是实现哥德巴赫猜想,但是出现编译时出现了问题,在此标记
 
 
[root@localhost baili]# gcc 18.c -o 18
/tmp/ccl4V3ho.o: In function `main':
18.c:(.text+0xbd): undefined reference to `sqrt'
18.c:(.text+0xcb): undefined reference to `floor'
18.c:(.text+0x11b): undefined reference to `sqrt'
18.c:(.text+0x123): undefined reference to `floor'
collect2: ld returned 1 exit status
我已经包含了头文件 math.h
不知道为什么?
 

#include <math.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    int i,j,num;
    int p,q,flagp,flagq;
    printf("please intput s plus integer:");
    scanf("%d",&num);
    if(((num%2)!=0)||(num<=4))
        printf("input data erro!\n");
    else
    {
        p=1;
        do
        {
            p = p+1;
            q = num-p;
            flagp=1;
            flagq=1;
            for(i=2;i<=(int)(floor(sqrt((double)(p))));i++)
            {
                if((p%i)==0)
                {
                    flagp = 0;
                    break;
                }
            }
        
        j = 2;
        while (j<=(int)(floor(sqrt((double)(q)))))
        {
            if((q%j)==0)
            {
                flagq = 0;
                break;
            }
            j++;
        }
        }while(flagp*flagq == 0);
    printf("%d = %d +%d \n",num,p,q);
    }

}


阅读(3907) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

xuqiang15732013-02-22 09:55:55

应该是没有库文件支持,在vc下就可以编译通过;
这里if(((num%2)!=0)||(num<=4))应该要改成if(((num%2)!=0)&&(num<=4))
另外,需要手动加载数学库函数:gcc 18.c -o 18 -lm
参考答案:http://hi.baidu.com/tigerlau225/item/d517ffef788300d2ea34c9a4
敬礼

chinaunix网友2010-10-29 14:54:01

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com