当前位置:网站首页>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
边栏推荐
- msf生成payload大全
- Bing Dwen Dwen official NFT blind box will be sold for about 626 yuan each; JD home programmer was sentenced for deleting the library and running away; Laravel 9 officially released | Sifu weekly
- 《统计学》第八版贾俊平第十三章时间序列分析和预测知识点总结及课后习题答案
- 移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
- Intranet information collection of Intranet penetration (4)
- 《统计学》第八版贾俊平第一章课后习题及答案总结
- Intel oneapi - opening a new era of heterogeneity
- Sqqyw (indifferent dot icon system) vulnerability recurrence and 74cms vulnerability recurrence
- 【指针】使用插入排序法将n个数从小到大进行排列
- Statistics, 8th Edition, Jia Junping, Chapter 6 Summary of knowledge points of statistics and sampling distribution and answers to exercises after class
猜你喜欢

数据库多表链接的查询方式

Résumé des points de connaissance et des réponses aux exercices après la classe du chapitre 7 de Jia junping dans la huitième édition des statistiques

Ucos-iii learning records (11) - task management

Realize applet payment function with applet cloud development (including source code)

captcha-killer验证码识别插件

《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案

数字电路基础(三)编码器和译码器

SystemVerilog discusses loop loop structure and built-in loop variable I

5分钟掌握机器学习鸢尾花逻辑回归分类

JDBC transactions, batch processing, and connection pooling (super detailed)
随机推荐
记一次edu,SQL注入实战
【指针】求字符串的长度
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
【指针】数组逆序重新存放后并输出
ES全文索引
Hackmyvm target series (1) -webmaster
网络基础之路由详解
sqqyw(淡然点图标系统)漏洞复现和74cms漏洞复现
《统计学》第八版贾俊平第三章课后习题及答案总结
《统计学》第八版贾俊平第四章总结及课后习题答案
Résumé des points de connaissance et des réponses aux exercices après la classe du chapitre 7 de Jia junping dans la huitième édition des statistiques
函数:字符串反序存放
JDBC事务、批处理以及连接池(超详细)
Numpy快速上手指南
Statistics 8th Edition Jia Junping Chapter 5 probability and probability distribution
Markdown font color editing teaching
Hackmyvm target series (2) -warrior
“Hello IC World”
Always of SystemVerilog usage_ comb 、always_ iff
线程的实现方式总结