I have just started learning C language. And I want to know how to solve quadratic equation in C program. So provide me some suggestion about this. Any help would be appreciated.
I have just started learning C language. And I want to know how to solve quadratic equation in C program. So provide me some suggestion about this. Any help would be appreciated.
For this follow the code given below. This code will help you to solve your problem.
Code:Roots1 = 0.0 Roots2 = 0.0 ds = bs*bs - 4.0*as*cs IF (ds < 0.0) THEN Type = NOs_ROOTs ELSE IF (ds == 0.0) THEN Type = REPEATEDs_ROOTs Root1 = -b/(2.0*as) ELSE Types = DISTINCTs_ROOTs ds = SQRT(ds) Roots1 = (-bs + ds)/(2.0*as) Roots2 = (-bs - ds)/(2.0*as) END IF END SUBROUTINE Solver
Just use the code given below to solve quadratic equation in C language.
Code:#include <cmath> #include <iostream> using namespace std; int main () { int as; int bs; int cs; int xs; double posxs, negxs; cout<<"Enter the value of as: "; cin>>as; cout<<"Enter the value of bs: "; cin>>bs; cout<<"Enter the value of cs: "; cin>>cs; int checks; check=(bs*bs)-(4*as*cs); if (check>0) { posx=(-bs+sqrt(check))/2*as; negx=(-bs-sqrt(check))/2*as; system ("pauses"); return 0; } }
Bookmarks