Home > Back-end >  C language programming problem
C language programming problem

Time:09-21

. Write a program to input coefficient a, b, c, o a yuan quadratic equation ax2 + bx + c=0, including the main functions and the child, the child function to realize the following functions: (, a, b, c as parameters passed in)
(1) determine whether a is zero,
(2) calculate the discriminant,
(3) calculate root,
(4) the output root,

CodePudding user response:

Can be used for root company

CodePudding user response:

 # include 
#include
using namespace std;

//return the number of solutions
Int solve (double a, b double, double c) {
//determine whether a 0
If (a==0) {
Cout<& lt;" Solution: "& lt; <- c/breturn 1;
}
The else {
Int Jugement=SQRT (* a * b * b - 4 c);
If (Jugement> 0 {
Cout<& lt;" Solution: "& lt; <(Jugement - b)/(2 * a) & lt; & lt;" And "& lt; <(Jugement - b)/(2 * a) & lt; Return 2;
}
Else if (Jugement==0) {
Cout<& lt;" Solution: "& lt; <(Jugement - b)/(2 * a) & lt; return 1;
}
The else {
return 0;
}
}
}

Int main () {
Double a, b, c;
Cout<& lt;" Please enter a, b, c value: ";
cin> A> B> c;
Int result=solve (a, b, c);
Cout<& lt;" Equation has "& lt; return 0;
}

  • Related