Untitled
unknown
plain_text
2 years ago
491 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){
r1 = -b + sqrt( pow(b,2) - 4*a*c )/ (2*a);
r2 = -b - sqrt( pow(b,2) - 4*a*c )/ (2*a);
if(!r1 || !r2) {
cout << "error the root doesn't exist";
return 1;
} else return 0;
}Editor is loading...
Leave a Comment