Yddd


私信TA

用户名:guo16ding

访问量:5921

签 名:

等  级
排  名 7435
经  验 1262
参赛次数 0
文章发表 8
年  龄 0
在职情况 学生
学  校 上海应用技术大学
专  业

  自我简介:

解题思路:调用 math.h 函数库 使用求根公式

注意事项:算delta时注意运算优先级、输出x1,x2时保留小数

参考代码:

#include<stdio.h>

#include<math.h>

void sqrt1(int a,int b,int c)

{

float x1,x2;

int delta = b*b-4*a*c;

x1= (-b + sqrt(delta))/(2*a);

x2= (-b - sqrt(delta))/(2*a);

printf("x1=%.3f x2=%.3f",x1,x2);

}

void sqrt2(int a,int b,int c)

{

int x1 , x2 ;

x1 = -b/(2*a);

x2 = x1;

printf("x1=%d x2=%d",x1,x2);

}

void sqrt3(int a,int b,int c)

{

float x1 , x2 ;

int delta = b*b-4*a*c;

x1 = -b/(2.0*a);

x2 = sqrt(-delta)/(2.0*a);

printf("x1=%.3f+%.3fi ",x1,x2);

printf("x2=%.3f-%.3fi",x1,x2);

}

int main()

{

int a , b , c;

scanf("%d %d %d",&a,&b,&c);

if(b*b-4*a*c>0)

{

sqrt1(a,b,c);

}

if(b*b-4*a*c==0)

{

sqrt2(a,b,c);

}

if(b*b-4*a*c<0)

{

sqrt3(a,b,c);

}

return 0;

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区