当前位置:首页 » 编程语言 » 用c语言写方程
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

用c语言写方程

发布时间: 2022-08-29 09:44:58

㈠ 怎么利用c语言解方程

#include"math.h"
typedefstruct{
double*coef;
intn;
}poly;
doubledfx(poly*p,doublev){
doublet=v;
doubler=0;
double*coef=p->coef;
inti;
r+=coef[1];
for(i=2;i<p->n;i++){
r+=coef[i]*i*t;
t*=v;
}
returnr;
}
doublefx(poly*p,doublev){
doublet=v;
doubler=0;
double*coef=p->coef;
inti;
r+=coef[0];
for(i=1;i<p->n;i++){
r+=coef[i]*t;
t*=v;
}
returnr;
}
doublepolyroot(poly*p,doublex0){
doublex=x0-1;
intn=0;
while(fabs(x-x0)>1e-12&&n++<100){
doubledx0=dfx(p,x0);
x=x0;
if(dx0)
x0-=fx(p,x0)/dx0;
else
x0-=0.1;
printf("inter:%df(%lf)=%lf ",n,x0,fx(p,x0));
}
returnx0;
}


intmain()
{
doublec[4]={-6,3,-4,2};
polyd={c,4};
polyroot(&d,1.5);
return0;
}

㈡ C语言 写一个解方程的程序

#include
<stdio.h>
#include
<math.h>

double
x1,x2,p;
float
file1(float
a,float
b)
{

x1=(-b+sqrt(p))/2*a;

x2=(-b-sqrt(p))/2*a;

return
0;
}
float
file2(float
a,float
b)
{

x1=x2=(-b+sqrt(p))/2*a;

return
0;
}
void
main()
{

float
a,b,c;

printf("请依次输入方程的三个系数:\n");

scanf("%f%f%f",&a,&b,&c);

p=b*b-4*a*c;

printf("方程是:%.1f*x*x
+
%.1f*x
+
%.1f
=
0\n",a,b,c);

if(p>0)

{

file1(a,b);

printf("X1=%f\tX2=%f\n",x1,x2);

}

else
if(p==0)

{

file2(a,b);

printf("X1=%f\tX2=%f\n",x1,x2);

}

else
printf("方程无解");
}

㈢ 如何用C语言写以下方程

double x3 = x*x*x;
doublex2 = x*x;
double y2 = y*y;
y2_div_x2 = y2/x2;

double result = (x3+y2_div_x2)/(y2+1);
或者
math.h文件里的pow(x,y)用于求x的y次方,用它做也可以
比如pow(x,3)即为x的3次方

㈣ 如何用C语言程序解方程

上课时编的,测试过可用。/* Note:Your choice is C IDE */
#include "stdio.h"
#include <math.h>
void main()
{
int a,b,c,d,e;
e=1;
while (e)
{printf("求一个一元二次方程的根");
printf("ax^2+bx+c=0\n");
printf("请输入a=");
scanf("%d",&a);
if(a==0)
{
break;
}printf("请输入b=");
scanf("%d",&b);
printf("请输入c=");
scanf("%d",&c);
d=b*b-4*a*c;
if(d<0)
{
printf("无实数解\n");
}
else if(d==0)
{
printf("只有一个根为:%f\n",-b/(2.0*a));
}
else
{printf("有两个根为:%f%f\n",(-b+sqrt(e))/(2.0*a),(-b-sqrt(e))/(2.0*a));
}}
}

㈤ 用c语言写二元一次方程

printf("该一元二次方程有两个解,x1=%f,x2=%f
",x1,x2);//你引号打错了啊。。。

㈥ c语言求方程

#include<stdio.h>
#include<math.h>
main()
{
doublea,b,c,d,x1,x2;
while(1){
scanf("%lf%lf%lf",&a,&b,&c);
d=b*b-4*a*c;
if(d<0)printf("此方程无实根! ");
elseif(d==0)printf("此方程有一个实根为:%lf ",-b/(2*a));
elseprintf("此方程有两个实根为分别为:%lf %lf ",(-b-sqrt(d))/(2*a),(-b+sqrt(d))/(2*a));
}
}

刚写的一个,如图所示,望采纳。。。。。。

㈦ c语言写一个方程

# include <stdio.h>
void draw_pyramid(int size)
{
int i,j;
for(i=0;i<size;i++)//'*'的总层数
{
for(j=0;j<size-i-1;j++)//打印第i行最前面的空格
printf(" ");
for(j=0;j<i+1;j++)//打印第i行的'*'
printf("* ");
printf("\n");
}
}
int main()
{
draw_pyramid(6);
}

㈧ 用c语言解方程组

/*

1 -2 1 -1 -2 4

交点坐标为(1.22,0.05),(-1.22,4.95)

Press any key to continue

*/

#include<stdio.h>
#include<math.h>

doubleValue(doublex,doublea,doubleb,doublec){
returna*x*x+b*x+c;
}

intmain(){
doublex1,y1,x2,y2;
doublea,b,c,d,e,f,delta;
scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f);
delta=(b-e)*(b-e)-4*(a-d)*(c-f);
if(delta<0){
printf("二抛物线无交点。 ");
return0;
}
x1=(-(b-e)+sqrt(delta))/(2.0*(a-d));
x2=(-(b-e)-sqrt(delta))/(2.0*(a-d));
y1=Value(x1,a,b,c);
y2=Value(x2,a,b,c);
printf("交点坐标为(%.2lf,%.2lf),(%.2lf,%.2lf) ",x1,y1,x2,y2);
return0;
}

㈨ 如何用C语言解二元一次方程组

设计思路如下:

1、问题描述:

给定一个二元一次方程组,形如:

a * x + b * y = c;

d * x + e * y = f;

x,y代表未知数,a, b, c, d, e, f为参数。

求解x,y。

2、数据规模和约定:

0 <= a, b, c, d, e, f <= 2147483647。

3、设计思路:

二元一次方程组是由两个含有两个未知数的方程组成的,要求解,就要把二元转化为一元。由二元一次方程组的解法思想知,要把二元转化为一元.

实现的功能代码如下:

因为在求解过程中只有数之间的运算,而没有整个式子的运算,因此这种方法被广泛地用于计算机中。