当前位置:网站首页>Functions: Finding Roots of equations
Functions: Finding Roots of equations
2022-07-06 14:35:00 【|Light|】
requirement
Programming , Find the equation ax2+bx+c=0 The root of the , Solve with three functions respectively b2-4ac Greater than 0, be equal to 0 And less than 0 Root of time .
Code
#include<stdio.h>
#include<math.h>
#define EPSILON 1E-6
// Calculate and output two unequal real roots
void fun1(double a,double b,double c)
{
double x1,x2;
// Please add code below
// ********** Begin **********
int s = b*b-4*a*c;
if(s>0)
{
x1 = ((0-b)+sqrt(s))/(2*a);
x2 = ((0-b)-sqrt(s))/(2*a);
}
// ********** End **********
printf(" The equation has two unequal real roots :%.2f,%.2f\n",x1,x2);
}
// Calculate and output two equal real roots
void fun2(double a,double b,double c)
{
double x1,x2;
// Please add code below
// ********** Begin **********
int s = b*b-4*a*c;
if(s==0)
{
x1 = (0-b)/(2*a);
x2 = (0-b)/(2*a);
}
// ********** End **********
printf(" The equation has two equal real roots :%.2lf,%.2lf\n",x1,x2);
}
// Calculate and output two conjugate complex roots
void fun3(double a,double b,double c)
{
double p,q;
// Please add code below
// ********** Begin **********
int s = b*b-4*a*c;
if(s<0)
{
p = (0-b)/(2*a);
q = sqrt(0-s)/(2*a);
}
// ********** End **********
printf(" The equation has two conjugate complex roots :%.2lf+%.2lfi,%.2lf-%.2lfi\n",p,q,p,q);
}
// Calculate the root of the equation
void fun(double a,double b,double c)
{
double delta=b*b-4*a*c;
if(fabs(delta)>EPSILON)
{
if(delta>0)
fun1(a,b,c);
else
fun3(a,b,c);
}
else
fun2(a,b,c);
}
test
Test input
3 6 8
Output
The equation has two conjugate complex roots :-1.00+1.29i,-1.00-1.29i
边栏推荐
- Only 40% of the articles are original? Here comes the modification method
- Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
- 外网打点(信息收集)
- 使用 flask_whooshalchemyplus jieba实现flask的全局搜索
- 数字电路基础(一)数制与码制
- 《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
- List and data frame of R language experiment III
- Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
- XSS之冷门事件
- Mathematical modeling idea of 2022 central China Cup
猜你喜欢
关于交换a和b的值的四种方法
Detailed explanation of network foundation
外网打点(信息收集)
数字电路基础(三)编码器和译码器
Statistics, 8th Edition, Jia Junping, Chapter 11 summary of knowledge points of univariate linear regression and answers to exercises after class
JDBC事务、批处理以及连接池(超详细)
New version of postman flows [introductory teaching chapter 01 send request]
内网渗透之内网信息收集(三)
Record an API interface SQL injection practice
Library management system
随机推荐
【指针】使用插入排序法将n个数从小到大进行排列
How does SQLite count the data that meets another condition under the data that has been classified once
【指针】统计一字符串在另一个字符串中出现的次数
网络基础详解
JDBC事务、批处理以及连接池(超详细)
Hackmyvm target series (2) -warrior
指针--剔除字符串中的所有数字
函数:求方程的根
浅谈漏洞发现思路
Statistics, 8th Edition, Jia Junping, Chapter VIII, summary of knowledge points of hypothesis test and answers to exercises after class
攻防世界MISC练习区(SimpleRAR、base64stego、功夫再高也怕菜刀)
Intel oneapi - opening a new era of heterogeneity
2022华中杯数学建模思路
ES全文索引
sqqyw(淡然点图标系统)漏洞复现和74cms漏洞复现
Sentinel overall workflow
Internet Management (Information Collection)
Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence
Intranet information collection of Intranet penetration (5)
. Net6: develop modern 3D industrial software based on WPF (2)