Skip to content

Commit

Permalink
Merge pull request #1748 from swastik-akhil/SSOC-2-ShriDharayacharya
Browse files Browse the repository at this point in the history
Ssoc 2 Shri Dharayacharya
  • Loading branch information
Kumar-laxmi authored Jul 28, 2023
2 parents 444bc66 + 7c8b36f commit b29215b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
23 changes: 23 additions & 0 deletions C++/Maths/shriDharacharya.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <cmath>

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;
}
23 changes: 23 additions & 0 deletions C/Maths/shriDharacharya.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
#include <math.h>

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;
}
23 changes: 23 additions & 0 deletions Java/Maths/ShriDharacharya.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
16 changes: 16 additions & 0 deletions Python/Maths/ShriDharacharya
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit b29215b

Please sign in to comment.