您的位置:首页 > 其它

求方程 的根,用三个函数分别求当b2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。

2012-02-29 20:05 435 查看
View Code

#include<stdio.h>
#include<math.h>
void yishigen(float m,float n,float k)
{
float x1,x2;
x1=(-n+(float)sqrt(k))/(2*m);
x2=(n-(float)sqrt(k))/(2*m);
if(x1==x2)
printf("=%.3f\n",x1);
else
printf("two shigen is x1=%.3f and x2=%.3f\n",x1,x2);
}
void denggen(float m,float n,float k)
{
float x;
x=(float)(-n/(2*m));
printf("denggen is x=%.3f\n",x);
}
void xugen(float m,float n,float k)
{
float x,y;
x=(float)n/(2*m);
y=(float)sqrt(-k)/(2*m);
printf("two xugen is x1=%.3f+%.3fi and x2=%.3f-%.3fi\n",x,y,x,y);
}
int main()
{
float a,b,c,q;
printf("input a b c is ");
scanf("%f%f%f",&a,&b,&c);
printf("\n");
if(a==0)
if(b==0)
if(c=0)
printf("所有实数");
else
{printf("wugen\n");return 0;}
else
{printf("x=%.3f\n",-c/b);return 0;}
q=b*b-4*a*c;
if(q>0)
yishigen(a,b,q);
else
if(q==0)
denggen(a,b,q);
else
xugen(a,b,q) ;
return 0;
}


2.求方程 的根,用三个函数分别求当b2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。
#include"math.h"
float yishigen(float m,n,k)
{float x1,x2;
x1=(-n+sqrt(k))/(2*m);
x2=(n-sqrt(k))/(2*n);
printf("two shigen is x1=%.3f and x2=%.3f\n",x1,x2);
}
float denggen(m,n);
{float x;
x=-n/(2*m);
printf("denggen is x=%.3f\n",x);
}
float xugen(m,n,k)
{float x,y;
x=n/(2*m);
y=sqrt(-k)/(2*m);
printf("two xugen is x1=%.3f+%.3fi and x2=%.3f-%.3fi\n",x,y,x,y);
}
main()
{float a,b,c,q;
printf("input a b c is ");
scanf("%f,%f,%f",&a,&b,&c);
printf("\n");
q=b*b+4*a*c;
if(q<0) yishlgen(a,b,q);
else if(q=0) donggen(a,b);
else xugan(a,b,q)
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐