当前位置:网站首页>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
边栏推荐
- Hcip -- MPLS experiment
- Load balancing ribbon of microservices
- 攻防世界MISC练习区(gif 掀桌子 ext3 )
- Uibutton status exploration and customization
- Intranet information collection of Intranet penetration (5)
- Solutions to common problems in database development such as MySQL
- 浙大版《C语言程序设计实验与习题指导(第3版)》题目集
- Network technology related topics
- 我的第一篇博客
- 《统计学》第八版贾俊平第一章课后习题及答案总结
猜你喜欢
Uibutton status exploration and customization
Statistics 8th Edition Jia Junping Chapter 3 after class exercises and answer summary
Build domain environment (win)
Statistics 8th Edition Jia Junping Chapter 7 Summary of knowledge points and answers to exercises after class
《统计学》第八版贾俊平第八章假设检验知识点总结及课后习题答案
Chain team implementation (C language)
Based on authorized access, cross host, and permission allocation under sqlserver
Constants, variables, and operators of SystemVerilog usage
Hackmyvm target series (2) -warrior
servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。
随机推荐
Chain team implementation (C language)
《统计学》第八版贾俊平第三章课后习题及答案总结
captcha-killer验证码识别插件
5分钟掌握机器学习鸢尾花逻辑回归分类
How does SQLite count the data that meets another condition under the data that has been classified once
关于超星脚本出现乱码问题
图书管理系统
Constants, variables, and operators of SystemVerilog usage
Build domain environment (win)
List and data frame of R language experiment III
[issue 18] share a Netease go experience
《统计学》第八版贾俊平第十四章指数知识点总结及课后习题答案
Binary search tree concept
The difference between layer 3 switch and router
【指针】求字符串的长度
Network technology related topics
【指针】删除字符串s中的所有空格
关于交换a和b的值的四种方法
WEB漏洞-文件操作之文件包含漏洞
Sword finger offer 23 - print binary tree from top to bottom