当前位置:网站首页>Find the root of equation ax^2+bx+c=0 (C language)
Find the root of equation ax^2+bx+c=0 (C language)
2022-07-07 10:34:00 【Pu Yu Mu Zhi】
List of articles
One 、 subject
Find the equation ax2+bx+c=0 The root of the , use 3 When two functions are solved separately :bx2-4ac Greater than 0、 be equal to 0 And less than 0 And output the result . Enter... From the main function a,b,c Value .
Two 、 Code and results
1. Code
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
float x1,x2,t,p,q;
int main()
{
void Greater_than_Zero(float a,float b);
void Equal_to_Zero(float a,float b);
void Smaller_than_zero(float a,float b);
float a,b,c;
printf(" Please enter a,b,c Value :\n");
scanf("%f,%f,%f",&a,&b,&c);
printf(" solve equations :%4.2f*x*x+%4.2f*x+%4.2f=0\n",a,b,c);
t=b*b-4*a*c;
if(t>0)
{
Greater_than_Zero(a,b);
printf("x1=%f\nx2=%f\n",x1,x2);
}
else if(t==0)
{
Equal_to_Zero(a,b);
printf("x1=x2=%f\n",x1);
}
else
{
Smaller_than_zero(a,b);
printf("x1=%f+%fi\nx2=%f-%fi\n",p,q,p,q);
}
return 0;
}
void Greater_than_Zero(float a,float b)
{
x1=(-b+sqrt(t))/(2*a);
x2=(-b+sqrt(t))/(2*a);
}
void Equal_to_Zero(float a,float b)
{
x1=x2=(-b)/(2*a);
}
void Smaller_than_zero(float a,float b)
{
p=-b/(2*a);
q=sqrt(-t)/(2*a);
}
2. Running results
(1) Two unequal real roots
(2) Two equal real roots
(3) The complex roots of two conjugates
边栏推荐
- 【作业】2022.7.6 写一个自己的cal函数
- CAS机制
- Some properties of leetcode139 Yang Hui triangle
- [daiy5] jz77 print binary tree in zigzag order
- Schnuka: machine vision positioning technology machine vision positioning principle
- Installation and configuration of slurm resource management and job scheduling system
- gym安装踩坑记录
- 想考中级软考,一般需要多少复习时间?
- Vs code specifies the extension installation location
- CC2530 zigbee IAR8.10.1环境搭建
猜你喜欢
BUUCTF---Reverse---reverse1
1321: [example 6.3] deletion problem (noip1994)
原型与原型链
P1223 queuing for water /1319: [example 6.1] queuing for water
使用 load_decathlon_datalist (MONAI)快速加载JSON数据
MySQL insert data create trigger fill UUID field value
leetcode-304:二维区域和检索 - 矩阵不可变
IIC基本知识
使用Tansformer分割三维腹部多器官--UNETR实战
Basic introduction of yarn and job submission process
随机推荐
Remote meter reading, switching on and off operation command
中级网络工程师是什么?主要是考什么,有什么用?
Multisim--软件相关使用技巧
多线程-异步编排
关于easyflash v3.3使用过程的记录
[牛客网刷题 Day6] JZ27 二叉树的镜像
The width of table is 4PX larger than that of tbody
【acwing】786. Number k
Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
Study summary of postgraduate entrance examination in August
2022年上半年5月网络工程师试题及答案
施努卡:机器人视觉抓取工作原理 机器视觉抓取
Application of OpenGL gllightfv function and related knowledge of light source
Kotlin realizes wechat interface switching (fragment exercise)
Some properties of leetcode139 Yang Hui triangle
软考中级电子商务师含金量高嘛?
MySQL insert data create trigger fill UUID field value
1323:【例6.5】活动选择
Trajectory planning for multi robot systems: methods and Applications Overview reading notes
555电路详解