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

查看所有标签

The Probabilistic Method

The Probabilistic Method

Noga Alon、Joel H. Spencer / Wiley-Interscience / 2008-8-11 / USD 137.00

Praise for the Second Edition : "Serious researchers in combinatorics or algorithm design will wish to read the book in its entirety...the book may also be enjoyed on a lighter level since the diffe......一起来看看 《The Probabilistic Method》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换