diff --git a/C++/Maths/shriDharacharya.cpp b/C++/Maths/shriDharacharya.cpp new file mode 100644 index 000000000..8e3f332c1 --- /dev/null +++ b/C++/Maths/shriDharacharya.cpp @@ -0,0 +1,23 @@ +#include +#include + +void ShriDharacharyaFormulae(double a, double b, double c) { + double compValue = pow(b, 2) - 4 * a * c; + double val1 = -b / (2 * a); + + if (compValue >= 0) { + double val2 = sqrt(compValue) / (2 * a); + std::cout << val1 + val2 << " and " << val1 - val2 << std::endl; + } else { + std::cout << "Imaginary roots" << std::endl; + } +} + +int main() { + double a, b, c; + std::cin >> a; + std::cin >> b; + std::cin >> c; + ShriDharacharyaFormulae(a, b, c); + return 0; +} diff --git a/C/Maths/shriDharacharya.c b/C/Maths/shriDharacharya.c new file mode 100644 index 000000000..5c45ecd95 --- /dev/null +++ b/C/Maths/shriDharacharya.c @@ -0,0 +1,23 @@ +#include +#include + +void ShriDharacharyaFormulae(double a, double b, double c) { + double compValue = pow(b, 2) - 4 * a * c; + double val1 = -b / (2 * a); + + if (compValue >= 0) { + double val2 = sqrt(compValue) / (2 * a); + printf("%lf and %lf\n", val1 + val2, val1 - val2); + } else { + printf("Imaginary roots\n"); + } +} + +int main() { + double a, b, c; + scanf("%lf", &a); + scanf("%lf", &b); + scanf("%lf", &c); + ShriDharacharyaFormulae(a, b, c); + return 0; +} diff --git a/Java/Maths/ShriDharacharya.java b/Java/Maths/ShriDharacharya.java new file mode 100644 index 000000000..7ae13889c --- /dev/null +++ b/Java/Maths/ShriDharacharya.java @@ -0,0 +1,23 @@ +import java.util.Scanner; +import java.lang.Math; +public class ShriDharacharya { + public static void ShriDharacharyaFormulae(double a, double b, double c){ + double compValue = (Math.pow(b,2) - 4*a*c); + double val1 = -b/(2*a); + double val2 = Math.pow(compValue,.5)/(2*a); + if(compValue>=0){ + System.out.println((val1+val2) + "and " + (val1-val2)); + } + else{ + System.out.println("Imaginary roots"); + } + } + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + double a = scan.nextDouble(); + double b = scan.nextDouble(); + double c = scan.nextDouble(); + ShriDharacharyaFormulae(a,b,c); + scan.close(); + } +} diff --git a/Python/Maths/ShriDharacharya b/Python/Maths/ShriDharacharya new file mode 100644 index 000000000..fd6f31a37 --- /dev/null +++ b/Python/Maths/ShriDharacharya @@ -0,0 +1,16 @@ +import math + +def ShriDharacharyaFormulae(a, b, c): + compValue = (b ** 2) - 4 * a * c + val1 = -b / (2 * a) + + if compValue >= 0: + val2 = math.sqrt(compValue) / (2 * a) + print(val1 + val2, "and", val1 - val2) + else: + print("Imaginary roots") + +a = float(input()) +b = float(input()) +c = float(input()) +ShriDharacharyaFormulae(a, b, c)