-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1748 from swastik-akhil/SSOC-2-ShriDharayacharya
Ssoc 2 Shri Dharayacharya
- Loading branch information
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |