一元二次方程(C语言)

2017-08-25  本文已影响0人  你好667
# include <stdio.h>
# include <math.h>

int main(void)
{
    double a,b,c;
    double delta;
    double X1,X2; 
    char ch;
    
    do{
        printf("请输入一元二次方程的系数:\n");
        
        printf("a= ");
        scanf(" %lf" , &a);
        
        printf("b= ");
        scanf(" %lf" , &b);
        
        printf("c= ");
        scanf(" %lf" , &c);
        
        delta = b*b - 4*a*c ;
        
        if (delta > 0)  {
            
            X1 = (-b + sqrt(delta)) / (2*a);
            X1 = (-b + sqrt(delta)) / (2*a);
            printf("有两个解,x1 = %lf , x2 = %lf", X1 ,X2 );
            
        }else if (delta == 0){
            
            X1 = (-b + sqrt(delta)) / (2*a);
            printf("有两个解,x1 = x2 = %lf", X1 );
            
        }else {
            
            printf("无实数解");
            
        }

        printf("是否继续 (Y/N) :");
        scanf(" %c", &ch);

    } while (ch=='Y'|| ch=='y');
    
    
    return 0;
}
上一篇下一篇

猜你喜欢

热点阅读