设为首页 加入收藏

TOP

实现解一元二次方程(循环)(一)
2018-10-21 20:09:18 】 浏览:108
Tags:实现 一元二次方程 循环

// equation.cpp : Defines the entry point for the console application.
//


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <float.h>    // 定义了浮点型的无穷小常量 const float FLT_EPSILON=1.192092896e-07F;


/*
 *    The function to caculate a Real coefficient eqution's(ax^2+bx+c=0) root.
 *  IN:  a,b,c   ---- the three real coefficient,
 *  OUT: r1, r2  ---- the two real roots or the real part of the complex roots.
 *       i1, i2  ---- the image part of the complex roots.
 *  RET: the status of the equation.
 */
int equation1(float a, float b, float c, float* r1, float* r2, float* i1, float* i2);
int equation2(float a, float b, float c, float& r1, float& r2, float& i1, float& i2);

int main(int argc, char* argv[])
{
    float a;
    float b;
    float c;
    char xuanze;
    
    float r1;
    float r2;
    float i1;
    float i2;
    
    for(;;)
    {
    printf("是否进行一元二次方程计算?Y/N\n");
    scanf("%c",&xuanze);
    if(xuanze=='Y')
    {
    printf("Please input a,b,c of the equation ax^2+bx+c=0 [a b c Enter]: ");
    scanf("%f %f %f", &a, &b, &c);

    switch(equation2(a,b,c, r1, r2, i1, i2))
    {
    case 0:
        printf("The equation %gx^2+%gx+%g=0 has no roots.\n", a, b, c);
        break;
    case 1:
        printf("The equation %gx^2+%gx+%g=0 has one real root:\n \tx=%g.\n", a, b, c, r1);
        break;
    case 2:
        printf("The equation %gx^2+%gx+%g=0 has two real roots:\n \tx1=%g, \tx2=%g.\n", a, b, c, r1, r2);
        break;
    case 3:
        printf("The equation %gx^2+%gx+%g=0 has an arbitrary solution.\n", a, b, c);
        break;
    case 4:
        printf("The equation %gx^2+%gx+%g=0 has a pair of conjugate complex roots:\n\tx1=%g+%gi, \tx2=%g-%gi.\n", a, b, c, r1, i1, r1, i1);
        break;
    default:
        break;
       }
       _flushall();
    }
    else
    {
      return 0;
      
    }
   }
    
}



//    printf("选择的是%c\n",xuanze);



/*
 *    The function to caculate a Real coefficient eqution's(ax^2+bx+c=0) root.
 *  IN:  a,b,c   ---- the three real coefficient,
 *  OUT: r1, r2  ---- the two real roots or the real part of the
编程开发网

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇串口实现FIFO接受数据(V2) 下一篇动态规划(DP)入门之-------最长..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

array(4) { ["type"]=> int(8) ["message"]=> string(24) "Undefined variable: jobs" ["file"]=> string(32) "/mnt/wp/cppentry/do/bencandy.php" ["line"]=> int(214) }