二次方程 [英] quadratic equation

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

问题描述

大家好!


我是c编程的新生,我们得到了一个创建程序的任务,该程序吐出了二次方程的根源!


我试了一下,但似乎错了,这就是为什么我需要你的帮助!谢谢


公式为x =( - 1/2)* p + - sqrt(1/4)* p ^ 2 -q)及其(p, q)是我的数据。如果等式没有真正的根printf(它没有真正的根);


我的代码


通过调用来阻止它功能!!

//

//由Haidar Wahid提供

//

//


#pragma warning(禁用:4996)

#include< stdio.h>

#include< stdlib.h>

#include< math.h>


int squareRoot_of(int p,int q,double a); //原型


int main(){

int x,y;

double z;

z = 0.5;

x = 55;

y = 10;


printf("%d \ n%d \ n",squareRoot_of(x,y,z));


系统(暂停);

}


int squareRoot_of(int p,int q,double a)// def


{



return((-a * p)+ - sqrt(a * a * p * p - q));

}

Hi everyone !

i''m a freshmen in c programming, and we got an assignment to create a program that spit out the roots of an quadratic equation!

I''ve given it a try but it seems to be wrong somehow that''s why i need your help! thanks


the formula is x= (-1/2)*p +- sqrt(1/4)*p^2 -q) and its (p,q) is my in-data. if the equation does not have real root printf("itdoes not have real roots");

my code

obs its by calling a function !!
//
// by Haidar Wahid
//
//

#pragma warning (disable:4996)
#include <stdio.h>
#include<stdlib.h>
#include<math.h>

int squareRoot_of(int p, int q, double a); // prototype

int main() {
int x, y;
double z;
z = 0.5;
x = 55;
y = 10;

printf("%d\n%d\n", squareRoot_of(x,y,z));


system("pause");
}

int squareRoot_of(int p, int q, double a) // def

{


return ((-a*p) +- sqrt(a*a*p*p - q));
}

推荐答案

你想找到这类方程的真正根源吗?

a * x ^ 2 + b * x + c = 0.


如果是的话,我会尝试给你一个答案而不会泄露解决方案。

好​​的,你首先应该找到歧视,说D,这就是

D = b ^ 2 - 4 * a * c。


现在,您要测试D的案例。如果D> 0,那意味着有可能真正的根源。如果D = 0,那么只有一个真实的根。

如果D< 0,那么你可以简单地输出没有真正的根。

鉴于找到根的公式,比如说x1,x2,如果D> 0是:


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

x2 =( - b - sqrt(D))/ 2 * a


如果D = 0(来自上面的公式):

x =( - b)/ 2 * a


我认为你可以做出很好的解决方案!


希望它有所帮助!
Do you want to find real roots for this type of equation?
a * x^2 + b * x + c = 0.

If yes, I will try to give you an answer without revealing the solution.
OK, you first should find the discriminent, say D, and this is
D = b^2 - 4 * a * c.

Now, you want to test cases for D. If D > 0, then that means that there are
2 possible real roots. If D = 0, then there is only one real root.
If D < 0, then you can just simply output that there are no real roots.
Given that the formula for finding the roots, say x1, x2, if D > 0 is:

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

and if D = 0 is(which is derived from the above formula):
x = (-b) / 2 * a

I think that you can make a good solution!

Hope it helped!


非常感谢你很多zuko32!我马上开始,希望它有效!


坦克再次
thank you very much zuko32! I will start with it right away and hope it works !

tanks again


#pragma warning(禁用:4996)

#include< stdio.h>

#include< stdlib.h>

#include< math.h>


int squareRoot_of(int p,int q,double a,int d,int x1,int x2); //原型


int main(){

int x,y,c,v,g,h;

double b;

x = 7;

y = 2;

b = 0.5;

g = 0;

h = 0;

v =((b * b * x * x) - y);

c = squareRoot_of(x,y,b,g,h ,v);


printf("%d%d \ n",c);


system( 暂停);



}


int squareRoot_of(int p,int q,double a ,int d,int x1,int x2)// def


{


d =((a * a * p * p) - q);


if(d> = 0){


printf("%d%d \ n,p ,q);

}

其他

{

printf(没有root \ n ;);

}


x1 =((-a * p)+ sqrt((a * a * p * p)) - q);


x2 =( - a * p - sqrt((a * a * p * p) - q));


返回x1 ,x2;

}


您认为zuko32是什么?
#pragma warning (disable:4996)
#include <stdio.h>
#include<stdlib.h>
#include<math.h>

int squareRoot_of(int p, int q, double a, int d ,int x1, int x2); // prototype

int main() {
int x, y, c, v, g, h;
double b;
x = 7;
y = 2;
b = 0.5;
g = 0;
h = 0;
v = ((b*b*x*x) - y);
c = squareRoot_of( x,y,b,g,h,v);

printf("%d%d\n", c);


system("pause");



}

int squareRoot_of(int p, int q, double a, int d, int x1, int x2) // def

{

d = ((a*a*p*p) - q);

if (d >= 0) {

printf("%d%d\n",p,q);
}
else
{
printf("there are no roots\n");
}

x1 = ((-a*p) + sqrt((a*a*p*p)) - q);

x2 = (-a*p - sqrt((a*a*p*p) - q));

return x1, x2;
}


what do u think zuko32?


这篇关于二次方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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