B^2-4ac

    xiaoxiao2021-03-25  410

    问题 B: C语言-解方程

    时间限制: 1 Sec   内存限制: 128 MB 提交: 354   解决: 188 [ 提交][ 状态][ 讨论版]

    题目描述

    求方程 的根,用三个函数分别求当b^2-4ac大于0、等于0、和小于0时的根,并输出结果。从主函数输入a、b、c的值。

    输入

    a b c

    输出

    x1=? x2=?

    样例输入

    4 1 1

    样例输出

    x1=-0.125+0.484i x2=-0.125-0.484i

    提示

    #include <stdio.h> #include <stdlib.h> /* run this program using the console pauser or add your own getch, system("pause") or input loop */ int main(int argc, char *argv[]) { double a,b,c,d,e; double x1,x2,s,t,m,n,i,j; scanf("%lf %lf %lf",&a,&b,&c); s=b*b-4*a*c; t=sqrt(s); m=-b/(2*a); n=t/(2*a); if(s<0) { i=-s; d=sqrt(i)/(2*a); printf("x1=%.3f+%.3fi x2=%.3f-%.3fi",m,d,m,d);  } else{ printf("x1=%.3f+%.3f x2=%.3f-%.3f",m,n,m,n); } return 0; }

    转载请注明原文地址: https://ju.6miu.com/read-5237.html

    最新回复(0)