Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
0
#include <iostream> #include <stdlib.h> #include <math.h> using namespace std; //a(x*x) + bx + c = 0 /*solution (-b + sqrt((b*b) -4ac))/(2a) and (-b - sqrt((b*b) -4ac))/(2a) */ float find_D(float a,float b,float c) { return ((b*b) - (4*a*c)); } void quad_eq_sol(float a, float b, float c) { float D = find_D(a,b,c); float re = (-b)/(2*a); float im = (sqrt(abs(D)))/(2*a); if(D >= 0){ cout << "Value of X is: "<< re+im << " and " << re-im << endl; } else { cout << "Value of X is: "<< re << " + " << im << "i"<< " and " << re << " - "<< im << "i"<< endl; } } int main() { float a = 0; float b = 0; float c = 0; cin >> a >> b >> c; quad_eq_sol(a,b,c); return 0; }
29th Nov 2016, 9:22 AM
Abhishek Kumar
Abhishek Kumar - avatar