习题3.3--C语言程序设计第三版课后习题(苏小红)

计算一元二次方程的两个实根 x1,x2

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    float a,b,c,temp,x1,x2;
    printf("please input number:");
    scanf("%f,%f,%f",&a,&b,&c);
    temp = sqrt(b*b - 4*a*c);
    if(temp > 0)
    {
    x1 = ((-b)+temp)/(2*a);
    x2 = (b+temp)/(2*a);
    printf("the value of x1 and x2 is :%d, %d\n",x1,x2);
    }
    else
     printf("the value of x1 and x2 is error\n");
    return 0;
}
 

发布了67 篇原创文章 · 获赞 54 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/naturly/article/details/104846894
今日推荐