要求编写如下程序: 编写求方程ax+b=0 (a.b为常数)的根的程序 定采纳,送财富 最好写出程
要求编写如下程序:编写求方程ax+b=0(a.b为常数)的根的程序定采纳,送财富最好写出程序来...
要求编写如下程序: 编写求方程ax+b=0 (a.b为常数)的根的程序 定采纳,送财富 最好写出程序来
展开
1个回答
2014-08-01
展开全部
#include<stdio.h>
void solve_equation(int a, int b)
{
if(a==0)
{
if(b!=0) //if(a==0 && b!=0)
{
printf("Sorry,the expression is meaningless!\n");
}
else //if(a==0 && b==0)
printf("the root of the equation is any value~\n");
}
else
{
if(b==0)//if(a!=0 && b==0)
{
printf("the root of the equation is:x = 0 \n");
}
else //if(a!=0 && b!=0)
{
printf("the root of the equation is:x = %f \n", -b/(float)a);
}
}
}
int main()
{
int a;
int b;
printf("Please enter a and b(both of a and b are )\n");
scanf("%d%d", &a, &b);
printf("The equation as:%dx + %d = 0\n", a, b);
solve_equation(a, b);
return 0;
}
void solve_equation(int a, int b)
{
if(a==0)
{
if(b!=0) //if(a==0 && b!=0)
{
printf("Sorry,the expression is meaningless!\n");
}
else //if(a==0 && b==0)
printf("the root of the equation is any value~\n");
}
else
{
if(b==0)//if(a!=0 && b==0)
{
printf("the root of the equation is:x = 0 \n");
}
else //if(a!=0 && b!=0)
{
printf("the root of the equation is:x = %f \n", -b/(float)a);
}
}
}
int main()
{
int a;
int b;
printf("Please enter a and b(both of a and b are )\n");
scanf("%d%d", &a, &b);
printf("The equation as:%dx + %d = 0\n", a, b);
solve_equation(a, b);
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |