自己写的做练习,如果有问题多谢指点
4.2
#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include<cmath>
using namespace std;
void delta1(float, float);
void delta2(float, float);
void delta3(float, float);
float delta;
int main()
{
float a, b, c;
cout << "Please input three numbers:" << endl;
scanf_s("%f %f %f", &a, &b, &c);
delta = b * b - 4 * a*c;
if (delta > 0)
delta1(a, b);
else if (delta == 0)
delta2(a, b);
else if (delta < 0)
delta3(a, b);
return 0;
}
void delta1(float a, float b)
{
float x1, x2;
x1 = (-b + sqrt(delta)) / (2 * a);
x2 = (-b - sqrt(delta)) / (2 * a);
cout << "x1=" << x1 << " x2=" << x2;
}
void delta2(float a, float b)
{
float x;
x = (-b) / (2 * a);
cout << "x1=x2=" << x;
}
void delta3(float a, float b)
{
float xb, sb;
sb = (-b) / (2 * a);
xb = (sqrt(-delta)) / (2 * a);
cout << "x1=" << sb << "+" << xb << "i" << endl;
cout << "x2=" << sb << "-" << xb << "i" << endl;
}
4.3