2024-08-02 01:07:34

#include <iostream>
#include <math.h>
using namespace std;
int main()
{
cout<<"a b c的数值:\n";
float a,b,c;
cin>>a>>b>>c;
float deerta=b*b-4*a*c;
if(deerta<0)
cout<<"无解";
else if(deerta==0)
{
float x=(-b+sqrt(deerta))/2*a;
cout<<"一个根:"<<x;
}
else
{
float x1=(-b+sqrt(deerta))/2*a;
float x2=(-b-sqrt(deerta))/2*a;
cout<<"两个根分别是:"<<x1<<"和"<<x2;
}
return 0;
}
朋友,超纲了,能发个简单些的么
哥什么地方超纲了?
iostream
cout
忘了 哥 你用的是C语言 我用的是C++
我给你改成C语言的了!
#include <stdio.h>
#include <math.h>
int main()
{
printf("a b c的数值:\n");
float a,b,c;
scanf("%g%g%g",&a,&b,&c);
float deerta=b*b-4*a*c;
if(deerta<0)
printf("无解");
else if(deerta==0)
{
float x=(-b+sqrt(deerta))/2*a;
printf("一个根 %g",x);
}
else
{
float x1=(-b+sqrt(deerta))/2*a;
float x2=(-b-sqrt(deerta))/2*a;
printf("两个根 %g 和 %g",x1,x2);
}
return 0;
}
好,谢谢
2024-08-02 05:41:38