Untitled

mail@pastecode.io avatar
unknown
plain_text
19 days ago
491 B
3
Indexable
Never
#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;
    
}
Leave a Comment