C语言课后题,调用3个函数求2次方程的根,编写程序如下:#include#includemain(){void zero(float a,float b);void left();void right(float a,float b,float c);float a,b,c,d;printf("请输入a,b,c的值:\n");scanf("%f%f%f",&a,&b,&c);d=b
来源:学生作业帮助网 编辑:六六作业网 时间:2025/01/09 17:26:42
C语言课后题,调用3个函数求2次方程的根,编写程序如下:#include#includemain(){void zero(float a,float b);void left();void right(float a,float b,float c);float a,b,c,d;printf("请输入a,b,c的值:\n");scanf("%f%f%f",&a,&b,&c);d=b
C语言课后题,调用3个函数求2次方程的根,编写程序如下:
#include
#include
main()
{void zero(float a,float b);
void left();
void right(float a,float b,float c);
float a,b,c,d;
printf("请输入a,b,c的值:\n");
scanf("%f%f%f",&a,&b,&c);
d=b*b-4*a*c;
if(d=0)zero(a,b);
if(d0)right(a,b,c);
}
void zero(float a,float b)
{
printf("%f",-b/2*a);
}
void left()
{
printf("no roots!\n");
}
void right(float a,float b,float c)
{
float x1,x2;
x1=-b/2*a+sqrt(b*b-4*a*c);
x1=-b/2*a-sqrt(b*b-4*a*c);
printf("%f %f \n",x1,x2);
}
初学者求指点
C语言课后题,调用3个函数求2次方程的根,编写程序如下:#include#includemain(){void zero(float a,float b);void left();void right(float a,float b,float c);float a,b,c,d;printf("请输入a,b,c的值:\n");scanf("%f%f%f",&a,&b,&c);d=b
#include<stdio.h>
#include<math.h>
void zero(float a,float b);
void left();
void right(float a,float b,float c);
void main()
{
float a,b,c,d;
printf("请输入a,b,c的值:\n");
scanf("%f %f %f",&a,&b,&c);
d=b*b-4*a*c;
if(d==0)zero(a,b);
if(d<0)left();
if(d>0)right(a,b,c);
}
void zero(float a,float b)
{
printf("%f",-b/2*a);
}
void left()
{
printf("no roots!\n");
}
void right(float a,float b,float c)
{
float x1,x2;
x1=(-b+sqrt(b*b-4*a*c))/(2*a);
x2=(-b-sqrt(b*b-4*a*c))/(2*a);
printf("%f %f \n",x1,x2);
}