求方程 的根,用三個函數分別求當b2-4ac大於0、等於0、和小於0時的根,並輸出結果。從主函數輸入a、b、c的值。


View Code
#include<stdio.h>
#include<math.h>
void yishigen(float m,float n,float k)
{
float x1,x2;
x1=(-n+(float)sqrt(k))/(2*m);
x2=(n-(float)sqrt(k))/(2*m);
if(x1==x2)
printf("=%.3f\n",x1);
else
printf("two shigen is x1=%.3f and x2=%.3f\n",x1,x2);
}
void denggen(float m,float n,float k)
{
float x;
x=(float)(-n/(2*m));
printf("denggen is x=%.3f\n",x);
}
void xugen(float m,float n,float k)
{
float x,y;
x=(float)n/(2*m);
y=(float)sqrt(-k)/(2*m);
printf("two xugen is x1=%.3f+%.3fi and x2=%.3f-%.3fi\n",x,y,x,y);
}
int main()
{
float a,b,c,q;
printf("input a b c is ");
scanf("%f%f%f",&a,&b,&c);
printf("\n");
if(a==0)
if(b==0)
if(c=0)
printf("所有實數");
else
{printf("wugen\n");return 0;}
else
{printf("x=%.3f\n",-c/b);return 0;}
q=b*b-4*a*c;
if(q>0)
yishigen(a,b,q);
else
if(q==0)
denggen(a,b,q);
else
xugen(a,b,q) ;
return 0;
}

2.求方程 的根,用三個函數分別求當b2-4ac大於0、等於0、和小於0時的根,並輸出結果。從主函數輸入a、b、c的值。 
#include"math.h" 
float yishigen(float  m,n,k) 
{float x1,x2; 
x1=(-n+sqrt(k))/(2*m); 
x2=(n-sqrt(k))/(2*n); 
printf("two shigen is x1=%.3f and x2=%.3f\n",x1,x2); 

float denggen(m,n); 
{float x; 
x=-n/(2*m); 
printf("denggen is x=%.3f\n",x); 

float xugen(m,n,k) 
{float x,y; 
x=n/(2*m); 
y=sqrt(-k)/(2*m); 
printf("two xugen is x1=%.3f+%.3fi and x2=%.3f-%.3fi\n",x,y,x,y); 

main() 
{float a,b,c,q; 
printf("input a b c is "); 
scanf("%f,%f,%f",&a,&b,&c); 
printf("\n"); 
q=b*b+4*a*c; 
if(q<0) yishlgen(a,b,q); 
else if(q=0) donggen(a,b); 
else xugan(a,b,q)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2026 CODEPRJ.COM