View Code of Problem 42

#include<iostream>
#include<math.h>
using namespace std;
void fun1(double a,double b,double c,double k)
{
    double x1=(-b+sqrt(k))/2/a;
    double x2=(-b-sqrt(k))/2/a;
    printf("%.2lf %.2lf",x1,x2);
}

void fun2(double a,double b,double c,double k)
{
    k=-k;

    double x=-b/2/a;
    double x1=sqrt(k)/2/a;
    printf("%.2lf+%.2lfi %.2lf-%.2lfi",x,x1,x,x1);
}

int main()
{
    double a,b,c;
    cin>>a>>b>>c;
    double k=b*b-4*a*c;
    if(k>=0)fun1(a,b,c,k);
    else fun2(a,b,c,k);
    return 0;
}

Double click to view unformatted code.


Back to problem 42