解决线性方程的程序出现问题. [英] Problem with the program to solve linear equations.

查看:103
本文介绍了解决线性方程的程序出现问题.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的!第一时间尝试"if-else".就像我在上面说的那样,这是代码:

Yes! The frist time try "if-else". Like I said above, here is the code:

#include<stdio.h>
main()
   {
   int a,b,x;
   printf("\n Input a: ");
   scanf("%d",&a);
   printf("\n Input b: ");
   scanf("%d",&b);
   if (a=0)
      {
      if (b=0)
         printf("\nThe equation has unlimited result");
      else 
         printf("\nThe equation has no result");
      getch();
      }
   else
      {
      x=-b/a;
      printf("\nThe equation has only 1 result x= %d", x);
      getch();
      }
   }



问题是:我已经在Dev-C ++中成功编译.但是当我运行它时,程序在输入两个数字(a和b)后崩溃了(程序已停止工作...).


[edit]更正了缩进,因此流程很清晰-OriginalGriff [/edit]



The problem is: I have compiled successfully in Dev-C++. But when I run it, the program crash after input 2 numbers (a and b) (The program has stoped working...).


[edit]Indentation corrected so the flow is clear - OriginalGriff[/edit]

推荐答案

养成进行像这样的比较的习惯:
如果(0 == a)
如果您错误地这样做:
如果(0 = a)
编译将失败,因为无法分配0.
这种错误非常普遍,甚至专业程序员有时仍会犯此错误,但是上述技巧有助于避免寻找此类错误.
Make a habit of doing comparisons like this :
if (0 == a)
if you mistakenly do this :
if (0 = a)
compilation will fail because 0 cannot be assigned.
This kind of error is very common and even professional programmers still make this error sometimes, but the above trick helps avoid having to look for this kind of error.


这篇关于解决线性方程的程序出现问题.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆