當前位置:編程學習大全網 - 編程軟體 - C語言編程:求壹元二次方程的解,要求如下圖,咋編?

C語言編程:求壹元二次方程的解,要求如下圖,咋編?

代碼文本:

#include "stdio.h"

#include "math.h"

void fp(double a,double b,double t){

b/=(a+=a);

t=sqrt(t)/a;

printf("x1 = %g\nx2 = %g\n",-b+t,-b-t);

}

void fn(double a,double b,double t){

b/=(a+=a);

t=sqrt(-t)/a;

if(b)

printf("x1 = %g+%gi\nx2 = %g-%gi\n",-b,t,-b,t);

else

printf("x1 = %gi\nx2 = %gi\n",t,-t);

}

void f0(double a,double b){

printf("x1=x2 = %g\n",-b/(a+a));

}

int main(int argc,char *argv[]){?

double a,b,c,t;

printf("Enter a, b, c(R:)...\n");

if(scanf("%lf%lf%lf",&a,&b,&c)==3 && a)

(t=b*b-4*a*c)>0 ? fp(a,b,t) : t<0 ? fn(a,b,t) : f0(a,b);

else

printf("Input error, exit...\n");

return 0;

}

  • 上一篇:機器視覺軟件有哪些?
  • 下一篇:想問壹下,如果要開發壹個類似於圖像模式識別的系統,通常使用哪種語言效率比較高?
  • copyright 2024編程學習大全網