求线性方程解的C程序
我们可以应用软件开发的方法用C语言来求解一个变量的线性方程。
要求
方程应为ax+b=0的形式
a和b是输入,我们需要找到x的值
分析
这里,
的输入是A,B的值。
的输出是x值。
算法
参考下面给出的算法来找到线性方程的解。
Step 1. Start Step 2. Read a,b values Step 3. Call function Jump to step 5 Step 4. Print result Step 5:i. if(a == 0)Print value of c cannot be predictedElseCompute c=-b/aReturn cStep 6: Stop
程序
以下是寻找线性方程解的C程序-
#include输出结果#include float solve(float a, float b){ float c; if(a == 0){ printf("value of c cannot be predicted\n"); }else{ c = -b / a; } return c; } int main(){ float a, b, c; printf("\n enter a,b values: "); scanf("%f%f", &a, &b); c = solve(a, b); printf("\n linear eq of one variable in the form of ax+b = 0, if a=%f,b=%f,then x= %f",a,b,c); return 0; }
执行上述程序时,会产生以下结果-
enter a,b values: 4 8 linear eq of one variable in the form of ax+b = 0, if a=4.000000, b=8.000000, then x= -2.000000
热门推荐
2 红丝绒戚风蛋糕
3 夹心小甜点
4 南瓜甜点
6 粘米粉蒸蛋糕
7 酸奶华夫饼
9 红柚鸡蛋糕
10 葡萄干蛋糕
11 紫薯蛋糕卷
13 纸杯裱花小蛋糕
14 果酱奶酪蛋糕
15 日式樱花蔓越莓大福
16 草莓蛋糕卷
17 卡仕达长崎杯子蛋糕