// 选择结构和条件判断.cpp : Defines the entry point for the console application. #include "stdafx.h" #include <stdio.h> #include <math.h> int main() { float a,b,c,disc,x1,x2,p,q; scanf("%f%f%f",&a,&b,&c); disc=b*b-4*a*c; if(disc<0) printf("this equation hasn't real roots\n"); else { p=-b/(2.0*a); q=sqrt(disc)/(2.0*a); x1=p+q;x2=p-q; printf("real roots:\nx1=%7.2f\nx2=%7.2f\n",x1,x2); } return 0; }ps:求一元二次方程根的c程序代码!
发表评论: