#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,disc,x1,x2,p,q;
scanf("a=%f,b=%f,c=%f",&a,&b,&c);
disc=b*b-4*a*c;
p=-b/(2*a);
q=sqrt(disc)/(2*a);
x1=p+q;x2=p-q;
printf("x1=%5.2\nx2=%5.2f\n",x1,x2);
}
运行后
lin@linlan-desktop:~$ cc p.c
p.c: In function ‘main’:
p.c:11: warning: unknown conversion type character 0xa in format
/tmp/cc24OEO8.o: In function `main':
p.c:(.text+0x81): undefined reference to `sqrt'
collect2: ld returned 1 exit status
求详细的分析和解决方法
该修改哪儿,修改后的语句
谢谢,没有比我更新手的了
ubuntu下C语言学习遇到问题求助
-
- 帖子: 3
- 注册时间: 2010-09-29 21:37
- leeaman
- 帖子: 30702
- 注册时间: 2007-02-02 18:14
- 系统: debian sid
-
- 论坛版主
- 帖子: 21308
- 注册时间: 2007-08-02 20:29
- 系统: 窓辺とうこ
Re: ubuntu下C语言学习遇到问题求助
math.h gcc要加 -lm参数
- leeaman
- 帖子: 30702
- 注册时间: 2007-02-02 18:14
- 系统: debian sid
- 手中流沙
- 帖子: 280
- 注册时间: 2009-10-16 23:02
Re: ubuntu下C语言学习遇到问题求助
sqrt 函数不存在
- ChenFengyuan
- 帖子: 770
- 注册时间: 2008-03-23 0:39
Re: ubuntu下C语言学习遇到问题求助
还漏了,这个p.c:11: warning: unknown conversion type character 0xa in format
printf("x1=%5.2\nx2=%5.2f\n",x1,x2);
%5.2f
printf("x1=%5.2\nx2=%5.2f\n",x1,x2);
%5.2f