C 语言实例 - 一元二次方程

C 语言教程 · 2019-02-20 17:12:29

求一元二次方程:ax2+bx+c=0 的根。

输入三个实数a,b,c的值,且a不等于0。

实例

#include <stdio.h> #include <math.h> int main() { float a,b,c,x1,x2,d; printf("输入方程的三个系数:"); scanf("%f %f %f",&a,&b,&c); if(a!=0) { d=sqrt(b*b-4*a*c); x1=(-b+d)/(2*a); x2=(-b-d)/(2*a); if(x1<x2) printf("%0.2f %0.2f\n",x2,x1); else printf("%0.2f %0.2f\n",x1,x2); } return 0; }

运行结果:

输入方程的三个系数:1 2 1
-1.00 -1.00

点击查看所有 C 语言教程 文章: https://www.codercto.com/courses/l/17.html

查看所有标签

计算理论导论

计算理论导论

塞普斯 / 机械工业出版社 / 2002-8 / 39.0

This book——by a noted authority and educator in the field——presents computer science theory from a uniquely intuitive,“big picture”perspective.The author grounds his clear and interesting study on ......一起来看看 《计算理论导论》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

SHA 加密
SHA 加密

SHA 加密工具