第一题
2015-06-24 23:00
274 查看
#include <iostream> #include <cmath> using namespace std; double q(double,double,double); int main() {double a,b,c,p,x1,x2; cout<<"please enter a,b,c:"; cin>>a>>b>>c; p=-b/(2*a); try {x1=p+q(a,b,c); x2=p-q(a,b,c); cout<<"x1="<<x1<<endl<<"x2="<<x2<<endl; } catch(double d) {cout<<"a="<<a<<",b="<<b<<",c="<<c<<",disc="<<d<<",error!"<<endl;} cout<<"end"<<endl; } double q(double a,double b,double c) {double disc; disc=b*b-4*a*c; if (disc<0) throw disc; return sqrt(disc)/(2*a); }
<img src="https://img-blog.csdn.net/20150624230040354?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvbW9sdXpodWk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />
相关文章推荐
- JQuery实现下拉列表的联动
- 20150624 lintcode 总结 Lowest Common Ancestor
- SpringMVC入门实例及详细讲解
- 手斧Linux – 从LFS到Funtoo (42)
- LintCode Gas Station加油站
- u-boot2010.03 移植篇(二)-----修改start.S,支持nand启动
- 系统维护常用脚本
- hadoop2基本概念
- 深度学习及课题研究杂谈(一)
- 实验三:数字滤波器的设计
- 算法——链表问题集锦
- 使用超链接实现企业QQ在线客服
- 手斧Linux – 从LFS到Funtoo (41)
- char* 类型使用总结
- How to decide on the correct number of clusters?
- android 滑动返回
- 元素距离页面的绝对距离
- 手斧Linux – 从LFS到Funtoo (40)
- u-boot2010.03 分析篇(二)-----lowlevel.init.S
- 深入浅出Java回调机制