Cov txheej txheem:

Yuav ua li cas koj sau ib tug quadratic equation nyob rau hauv C ++?
Yuav ua li cas koj sau ib tug quadratic equation nyob rau hauv C ++?

Video: Yuav ua li cas koj sau ib tug quadratic equation nyob rau hauv C ++?

Video: Yuav ua li cas koj sau ib tug quadratic equation nyob rau hauv C ++?
Video: Mathematics with Python! Evaluating Polynomials 2024, Hlis ntuj nqeg
Anonim

Txoj Haujlwm 2: nrhiav ib qho b thiab c hauv qhov sib npaug plaub npaug

  1. # suav nrog
  2. # suav nrog
  3. int main() {
  4. ntab a, b, c ;
  5. ntab d, root1, root2;
  6. printf("Enter quadratic equation hauv format ax^2+bx+ c : ");
  7. scanf("%fx^2%fx%f", &a, &b, & c );
  8. d = b * b - 4 * a * c ;

Ib yam li ntawd, koj ua li cas sau ac program los nrhiav cov hauv paus ntawm kev sib npaug plaub npaug?

C qhov kev pab cuam los nrhiav cov hauv paus hniav ntawm ib qho kev sib npaug quadratic

  1. int main() { int a, b, c, d; ob lub hauv paus 1, hauv paus 2;
  2. printf("Enter a, b and c where a*x*x + b*x + c = 0"); scanf("%d%d%d", &a, &b, &c);
  3. printf("Log thawj = %.2lf", root1); printf("Second root = %2lf", root2); }

Tom qab, lo lus nug yog, dab tsi yog qhov kev ntxub ntxaug ntawm ib qho kev sib npaug plaub npaug? Cov neeg ntxub ntxaug yog ib feem nyob rau hauv lub square root nyob rau hauv lub quadratic formula , b²-4ac. Yog tias nws yog ntau tshaj 0, lub kev sib npaug muaj ob txoj kev daws teeb meem tiag tiag. Yog tias nws tsawg dua 0, tsis muaj kev daws teeb meem. Yog tias nws sib npaug rau 0, muaj ib qho kev daws teeb meem.

Ib sab ntawm qhov no, qhov kev sib npaug plaub npaug hauv C yog dab tsi?

Tus qauv qauv ntawm a quadratic equation yog:ax2 + bx + c = 0, qhov twg a, b c yog cov lej tiag tiag thiab a != 0. Lub sij hawm b 2 -4ac yog lub npe hu ua kev ntxub ntxaug ntawm a quadratic equation . Nws qhia qhov xwm ntawm cov hauv paus hniav.

Yuav ua li cas thiaj li tau txais cov hauv paus hauv C ++?

C++ program rau nrhiav Square Hauv paus ntawm tus lej. Rau xam Square Hauv paus ntawm tus lej peb muab tus lej los ntawm 0.5 vim square hauv paus ntawm ib tus lej txhais tau tias lub zog ntawm 1/2 thiab 1/2 = 0.5. Thiab ib txoj hauv kev rau qhov kev zov me nyuam no yog siv sqrt() muaj nuj nqi nws tau txhais ua ntej hauv lej. h header ntaub ntawv.