1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#include "stdafx.h"
#include <iostream>
#include <cmath>
using namespace std;
bool quad(int, int, int, double, double);
//int _tmain(int argc, _TCHAR* argv[])
int main()
{
int a,b,c;
double r1, r2;
cout << "enter a number";
cin >> a;
cout << "enter another number";
cin >> b;
cout << "enter the last number";
cin >> c;
if(quad(a,b,c,r1,r2))
{
cout << "solution found:"<< r1 << "," << r2 << endl;
}
else
{
cout << " no real solution!\n";
}
return 0;
}
bool quad( int a, int b, int c, double r1, double r2)
{
bool valid = true;
if( b*b-4*a*c > 0)
{
valid = false;
}
else
{
r1=(-b + sqrt * b-4*a*c))/(2*a);
r2=(-b - sqrt *b-4*a*c))/(2*a);
}
return valid;
}
|