Home Article Practice 一元二次方程编程

一元二次方程编程

2020-08-30 00:22  views:462  source:小键人255140    

#include <stdio.h>
#include <math.h>
int main(void)
{
//把三个系数保存到计算机中
int a = 3; // =不表示相等,表示赋值
int b = 4;
int c = 5;
double delta; //delta存放的是b*b - 4*a*c
double x1; //存放一元二次方程的其中一个解
double x2; //存放一元二次方程的另一个解
delta = b*b-4*a*c;
if(delta > 0)
{
x1 = (-b + sqrt(delta)) / (2*a);
x2 = (-b - sqrt(delta)) / (2*a);
printf("该一元二次方程有两个解, x1 = %f, x2 =%f\n",x1,x2);
}
else if (delta=0)
{
x1 = (-b)/(2*a);
x2 = x1; //右边赋给左边
printf("该一元二次方程有唯一解,x1=x2=%f\n", x1);
}
else
{
printf("无解\n");
}
}



Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)