|
本帖最后由 davidbill 于 2013-7-21 22:07 编辑
一元二次方程求根计算器
代码及程序
希望各位多多包涵
#include <stdafx.h>
#include <stdlib.h>
#define _CRT_SECURE_NO_WARNINGS
#include <math.h>
#include <Windows.h>
int main()
{
system("color 0a");
while (1==1)
{
printf("-----------------一元二次方程求根计算器-By-David-Zhang-Ver-0.2-----------------\n"
"请依次输入ax^2+bx+c=0中的a(回车)b(回车)c(回车)\n");
float a,b,c,d,e,f;
scanf_s("%f %f %f",&a,&b,&c);
if(a==0)
{
printf("您输入的是%.2fx+%.2f=0吗?",b,c);
system("pause");
printf("%.2f",(-c)/b);
system("pause");
}
else
{
printf("您输入的是%.2fx^2+%.2fx+%.2f=0吗?",a,b,c);
system("pause");
d=b*b-4*a*c;
e=(-b+sqrt(d))/(2*a);
f=(-b-sqrt(d))/(2*a);
printf("x1=%.2f,x2=%.2f",e,f);
system("pause");
}
}
}
|
|