解题思路:
注意事项:
参考代码:
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int dayu(double a,double b,double c)
{
double x1,x2,t;
t=b*b-4*a*c;
cout<<"x1="<<fixed<<setprecision(3)<<(-b)/(2*a)<<"+"<<sqrt(t)/(2*a)<<"i"<<" ";
cout<<"x2="<<(-b)/(2*a)<<"-"<<sqrt(t)/(2*a)<<"i"<<endl;
}
int dengyu(double a,double b,double c)
{
cout<<"x1="<<fixed<<setprecision(3)<<(-b)/(2*a)<<" ";
cout<<"x2="<<(-b)/(2*a)<<endl;
}
int xiaoyu(double a,double b,double c)
{
double t;
t=b*b-4*a*c;
cout<<"x1="<<fixed<<setprecision(3)<<(-b)/(2*a)<<"+"<<sqrt(-t)/(2*a)<<"i"<<" ";
cout<<"x2="<<(-b)/(2*a)<<"-"<<sqrt(-t)/(2*a)<<"i"<<endl;
}
int main()
{
double a,b,c,t;
cin>>a>>b>>c;
t=b*b-4*a*c;
if(t>0)
dayu(a,b,c);
else if(t==0)
dengyu(a,b,c);
else
xiaoyu(a,b,c);
}
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题7.3 (C语言代码)浏览:1215 |
C语言训练-尼科彻斯定理 (C语言代码)浏览:509 |
C语言训练-计算t=1+1/2+1/3+...+1/n (C语言代码)浏览:942 |
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:1110 |
C语言程序设计教程(第三版)课后习题4.9 (C语言代码)浏览:727 |
图形输出 (C语言代码)浏览:1422 |
DNA (C语言代码)浏览:440 |
C语言程序设计教程(第三版)课后习题10.5 (C语言代码)浏览:612 |
Quadratic Equation (C语言代码)浏览:1034 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:416 |