Untitled

mail@pastecode.io avatar
unknown
plain_text
18 days ago
498 B
7
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){

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;
    
}
Leave a Comment