当前位置:网站首页>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
边栏推荐
- 数字电路基础(三)编码器和译码器
- 《统计学》第八版贾俊平第十章方差分析知识点总结及课后习题答案
- How does SQLite count the data that meets another condition under the data that has been classified once
- Statistics 8th Edition Jia Junping Chapter 12 summary of knowledge points of multiple linear regression and answers to exercises after class
- 5分钟掌握机器学习鸢尾花逻辑回归分类
- Intranet information collection of Intranet penetration (5)
- Harmonyos application development -- address book management system telmanagesys based on listcontainer [phonebook][api v6]
- 循环队列(C语言)
- DVWA (5th week)
- 《统计学》第八版贾俊平第五章概率与概率分布
猜你喜欢
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
《统计学》第八版贾俊平第四章总结及课后习题答案
记一次api接口SQL注入实战
Database monitoring SQL execution
Solutions to common problems in database development such as MySQL
《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
网络基础之路由详解
Lintcode logo queries the two nearest saplings
JDBC事务、批处理以及连接池(超详细)
《英特尔 oneAPI—打开异构新纪元》
随机推荐
ES全文索引
内网渗透之内网信息收集(四)
Chain team implementation (C language)
数据库多表链接的查询方式
How does SQLite count the data that meets another condition under the data that has been classified once
An unhandled exception occurred when C connected to SQL Server: system Argumentexception: "keyword not supported:" integrated
JVM memory model concept
浙大版《C语言程序设计实验与习题指导(第3版)》题目集
SQL注入
《统计学》第八版贾俊平第十二章多元线性回归知识点总结及课后习题答案
What language should I learn from zero foundation. Suggestions
Sword finger offer 23 - print binary tree from top to bottom
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
WEB漏洞-文件操作之文件包含漏洞
Detailed explanation of network foundation
《统计学》第八版贾俊平第九章分类数据分析知识点总结及课后习题答案
【指针】求解最后留下的人
外网打点(信息收集)
List and data frame of R language experiment III
Overview of LNMP architecture and construction of related services