当前位置:网站首页>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
边栏推荐
- JDBC事务、批处理以及连接池(超详细)
- JDBC看这篇就够了
- Hcip -- MPLS experiment
- Intranet information collection of Intranet penetration (4)
- Interview Essentials: what is the mysterious framework asking?
- Sentinel overall workflow
- Hackmyvm target series (1) -webmaster
- ES全文索引
- Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
- Intel oneapi - opening a new era of heterogeneity
猜你喜欢
内网渗透之内网信息收集(一)
Ucos-iii learning records (11) - task management
Markdown font color editing teaching
《统计学》第八版贾俊平第三章课后习题及答案总结
An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated
Apache APIs IX has the risk of rewriting the x-real-ip header (cve-2022-24112)
Library management system
《统计学》第八版贾俊平第七章知识点总结及课后习题答案
Interview Essentials: what is the mysterious framework asking?
数字电路基础(三)编码器和译码器
随机推荐
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
【指针】求字符串的长度
Attack and defense world misc practice area (GIF lift table ext3)
Record once, modify password logic vulnerability actual combat
The most popular colloquial system explains the base of numbers
Pointeurs: maximum, minimum et moyenne
What language should I learn from zero foundation. Suggestions
攻防世界MISC练习区(gif 掀桌子 ext3 )
2022华中杯数学建模思路
【指针】求解最后留下的人
Intranet information collection of Intranet penetration (I)
5分钟掌握机器学习鸢尾花逻辑回归分类
函数:用牛顿迭代法求方程的根
Binary search tree concept
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
XSS (cross site scripting attack) for security interview
Hackmyvm target series (1) -webmaster
Data mining - a discussion on sample imbalance in classification problems
An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated
JDBC看这篇就够了