MOOC清华《程序设计基础》第1章第4题:求解方程

来源:互联网 发布:mac查看隐藏文件 编辑:程序博客网 时间:2024/05/01 13:03

题目描述

请编写程序计算输出 3x^2 -5x - 9 = 0 的正根。提示:使用一元二次方程求根公式来计算。(保留小数点后5位)

输入描述

输出描述

输出正根

//************************//*程序名:求解方程//*功 能:求解方程//*编制人:刘聪//*时 间:2017年1月18日//************************#include <iostream>#include <cmath>#include <iomanip>using namespace std;int main(){    cout<<fixed<<setprecision(5)<<( - (-5) + sqrt((-5) * (-5) - 4 * 3 * (-9))) / (2 * 3)<<endl;    return 0;}


阅读全文
0 0
原创粉丝点击