| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 792 人关注过本帖
标题:我的这个求根程序到底问题出在哪里了?
只看楼主 加入收藏
troyzyc
Rank: 1
等 级:新手上路
帖 子:108
专家分:0
注 册:2016-7-4
结帖率:56.6%
收藏
已结贴  问题点数:10 回复次数:2 
我的这个求根程序到底问题出在哪里了?
#include<stdio.h>
#include<math.h>

int main()
{double a,b,c;
double x1,x2,disc,realpart,imagpart,root;
disc=b*b-4*a*c;
realpart=-b/(2*a);
imagpart=sqrt(-disc)/(2*a);

printf("There is a equation :a*x*x+b*x+c=0\n");
printf("please enter a,b,c:");
scanf("%lf,%lf,%lf",&a,&b,&c);

if(fabs(a)<1e-6)
{printf("it is not a 二次方程!");
root=-(b/c);
printf("the root is %f\n",root);
}

else    /* (a!=0) */
{
   if(fabs(disc)>1e-6)
   {  if(disc>1e-6)
   {printf("it is a 二次方程!");
 x1=(-b+sqrt(b*b-4*a*c))/(2*a);
 x2=(-b-sqrt(b*b-4*a*c))/(2*a);
 printf("there are two roots: x1=%f,x2=%f",x1,x2);}
      else
      {printf("it is a 根为虚数的二次方程! it has two complex roots: ");
 printf("x1=%8.4lf+%8.4lfi\n",realpart,imagpart);
 printf("x2=%8.4lf-%8.4lfi\n",realpart,imagpart);}
}
   else
{printf("it has two equal root:%8.4lf\n",-b/(2*a));}

}

return 0;
}
搜索更多相关主题的帖子: double please include equation 
2016-11-10 18:00
linlulu001
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:20
帖 子:944
专家分:4047
注 册:2016-4-13
收藏
得分:1 
这提问也太不负责认了。
错就分好多种,例如:编译错,结果错,运行过程出错等等。
2016-11-10 20:37
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:9 
回复 楼主 troyzyc
disc=b*b-4*a*c;
realpart=-b/(2*a);
做这件事的时候a,b,c都还没有赋过值,不要指望得到想要的结果。你可以把这两个过程放在两个独立的函数里面,需要的时候再触发它。直接在main里面绝对不行的。
2016-11-10 21:25
快速回复:我的这个求根程序到底问题出在哪里了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015162 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved