Untitled
unknown
plain_text
2 years ago
498 B
12
Indexable
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
//Q1
double quad(double a, double b, double c, double &r1, double &r2);
//input:a,b,c
//output: r1,r2
//call-by-value: a,b,c
//call-by-reference: r1,r2
double quad(double a, double b, double c, double &r1, double &r2){
double d = pow(b,2) - 4*a*c;
r1 = -b + sqrt(d)/ (2*a);
r2 = -b - sqrt(d)/ (2*a);
if( a == 0 || d < 0 ) {
cout << "\nerror the root doesn't exist\n";
return 1;
} else return 0;
}Editor is loading...
Leave a Comment