| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 727 人关注过本帖, 1 人收藏
标题:求二元一次方程组x,y值。帮小弟看看有问题不? 小弟刚学到do..while循环,谢 ...
取消只看楼主 加入收藏
ciscoh3c
Rank: 1
等 级:新手上路
帖 子:14
专家分:7
注 册:2012-11-25
结帖率:100%
收藏(1)
已结贴  问题点数:20 回复次数:1 
求二元一次方程组x,y值。帮小弟看看有问题不? 小弟刚学到do..while循环,谢谢大神们
/*当a/d≠b/e 时,该方程组有一组解。   当a/d=b/e=c/f 时,该方程组有无数组解。   当a/d=b/e≠c/f 时,该方程组无解。*/


#include <stdio.h>


int  main(void)
{   
    char ch;
    double a,b,c,d,e,f,x,y,n,p,w,z,i,v;
    do
    {   
        printf("\n");
        printf("\n");
        printf("求二元一次方程ax+by+c=0\n");
        printf("              dx+ey+f=0的值\n");
        printf("\n");
        printf("\n");
        x = 0;    //把x的值初始化一下
        y = 0;    //把y的值初始化一下
        n = 0;
        p = 0;
        w = 0;
        z = 0;


        printf("请输入a的值:");
        scanf ("%lf",&a);
        printf("a = %lf\n",a);

        printf("请输入b的值:");
        scanf ("%lf",&b);
        printf("b = %lf\n",b);

        printf("请输入c的值:");
        scanf ("%lf",&c);
        printf("c = %lf\n",c);

        printf("请输入d的值:");
        scanf ("%lf",&d);
        printf("d = %lf\n",d);

        printf("请输入e的值:");
        scanf ("%lf",&e);
        printf("e = %lf\n",e);

        printf("请输入f的值:");
        scanf ("%lf",&f);
        printf("f = %lf\n",f);

        printf ("表达式一为:%lf*x+%lf*y+%lf=0\n",a,b,c);
        printf ("表达式二为:%lf*x+%lf*y+%lf=0\n",d,e,f);

        n = (d*c) - (a*f);
        p = (a*e) - (b*d);
        y = 1.0*n/p;

        w = (b*f)-(c*e);
        z = (a*e)-(b*d);
        x = 1.0*w/z;


        if (a==0 && b==0)

        {
            printf ("表达式不成立,此方程组错误!\n");
        }

        else if (d==0 && e==0)

        {
            printf ("表达式不成立,此方程组错误!\n");
        }

        else if ((1.0*a/d ==1.0*b/e) && (1.0*a/d != 1.0*c/f))
            printf ("此方程式无解!\n");  

        else if (1.0*a/d == 1.0*b/e == 1.0*c/f)   
            printf ("此方程式有无数个解!\n");
            

        else if (a==0 && d==0)
        {   
            double m,t;
            m = 1.0*b/e;
            t = 1.0*c/f;

            if (m==t)
            {
                y = -1.0*c/b;
                printf ("x=x任意值,y= %lf\n",y);
            }           
            else
                printf ("无解!\n");
        }


        else if (b==0 && e==0)
        {   
            double m,t;
            m = 1.0*a/d;
            t = 1.0*c/f;

            if (m==t)
            {
                x = -1.0*c/a;
                printf ("x= %lf,y取任意值\n",x);
            }           
            else
                printf ("无解!\n");
        }

        else if (1.0*a/d != 1.0*b/e)

        {
            y = 1.0*n/p;
            x = 1.0*w/z;
            printf ("x = %lf,y = %lf \n",x,y);
        }

        else
            printf ("此方程真的无解!\n");



        printf ("你想继续么(y/n):");
        scanf  (" %c",&ch);   //取字符时,%c前面要有空格

    } while ('y' == ch || 'Y'== ch);

    return 0;
}
搜索更多相关主题的帖子: include 方程组 
2012-11-29 23:49
ciscoh3c
Rank: 1
等 级:新手上路
帖 子:14
专家分:7
注 册:2012-11-25
收藏
得分:0 
好的。谢谢!
2012-11-30 12:26
快速回复:求二元一次方程组x,y值。帮小弟看看有问题不? 小弟刚学到do..while循 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021882 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved