美文网首页
一元二次方程(C语言)

一元二次方程(C语言)

作者: 你好667 | 来源:发表于2017-08-25 10:20 被阅读0次
    # 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;
    }
    

    相关文章

      网友评论

          本文标题:一元二次方程(C语言)

          本文链接:https://www.haomeiwen.com/subject/huqudxtx.html