解一元一次方程

wanslj 2011-10-17 11:32:02
能不能用c代码解一元一次方程?怎样解,求指点
...全文
289 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
初出茅庐之新 2011-10-18
  • 打赏
  • 举报
回复
#include <stdio.h>
#define N 10*e-6
int main()
{
float a, b;
printf("aX + b = 0\n");
printf("请输入a和b的值:\n");
scanf("%lf%lf", &a, &b);
if(a == N)
{
printf("输入有错误\n");
return 0;
}
printf("X=%f\n", -b/a);
return 0;
}
孤独小剑 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 zhongxianyao 的回复:]

#include <stdio.h>
int main()
{
double a, b;
printf("aX + b = 0\n");
printf("请输入a和b的值\n");
scanf("%lf%lf", &a, &b);
if(a == 0.0)
{
printf("输入有错误\n");
return 0;
}
printf("X=%f\n", ……
[/Quote]浮点数是不可以和0或者0.0这样的数判断是否为0的……
编程点滴 2011-10-18
  • 打赏
  • 举报
回复
#include <stdio.h>
int main()
{
double a, b;
printf("aX + b = 0\n");
printf("请输入a和b的值\n");
scanf("%lf%lf", &a, &b);
if(a == 0.0)
{
printf("输入有错误\n");
return 0;
}
printf("X=%f\n", -b/a);
return 0;
}
shuoshuo_mt 2011-10-18
  • 打赏
  • 举报
回复
#include<stdio.h>
void main()
{
//ax+b=0
float a,b,x;
printf("请输入a、b的值:\n");
scanf("%f %f",&a,&b);
x=-b/a;
printf("x=%f\n",x);
}
MATHPHYSIC 2011-10-18
  • 打赏
  • 举报
回复
#include<stdio.h>
void main()
{
float a,b,x;
printf("please input two num:\n");
scanf("%f%f",&a,&b);
printf("The Equations is %f*x+%f=0",a,b);
if(a==0)
{printf("The Equations is no root");
else
{
float x=-b/a;
printf("the root is %f",x);
}
}
如果还想要输出好看点,可以自己弄弄
MATHPHYSIC 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 shangdia520 的回复:]

#include<stdio.h>
void main()
{
float a,b,x;
printf("please input two num:\n");
scanf("%f%f",&a,&b);
float x=-b/a;
printf("the root is %f",x);
}
[/Quote]
如果用户输入a=0,你的输出处理不了
牛逼代码 2011-10-18
  • 打赏
  • 举报
回复
多看看潭浩强的书,这些都不在话下
shangdia520 2011-10-18
  • 打赏
  • 举报
回复
#include<stdio.h>
void main()
{
float a,b,x;
printf("please input two num:\n");
scanf("%f%f",&a,&b);
float x=-b/a;
printf("the root is %f",x);
}
shangdia520 2011-10-18
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jacicson1987 的回复:]
C/C++ code

#include <iostream>
using namespace std;
//ax+b = 0 一元一次方程。
int main()
{
double a,b;
cout << "Please input the two parameters a and b!"<<endl;
cin >>a >> b;
doubl……
[/Quote]
楼主说的是用C好不好
AndyZhang 2011-10-18
  • 打赏
  • 举报
回复
这个必须可以啊
小湿哥 2011-10-17
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;
//ax+b = 0 一元一次方程。
int main()
{
double a,b;
cout << "Please input the two parameters a and b!"<<endl;
cin >>a >> b;
double x = -b / a;
cout << "X: " << x <<endl;

}


这个很简单啦,如果是一元二次的,只需要改变 x = -b / a 公式,加个参数就行了额。。
無_1024 2011-10-17
  • 打赏
  • 举报
回复
x = - a / b

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧