-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAdd2Int.kt
More file actions
45 lines (35 loc) · 1.08 KB
/
Add2Int.kt
File metadata and controls
45 lines (35 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
fun main(args: Array<String>) {
val first: Int = 10
val second: Int = 20
val sum = first + second
println("The sum is: $sum")
}
ROOTS FOR QUADRATIC EQUATION
fun main(args: Array<String>) {
val a = 2.3
val b = 4
val c = 5.6
val root1: Double
val root2: Double
val output: String
val determinant = b * b - 4.0 * a * c
// condition for real and different roots
if (determinant > 0) {
root1 = (-b + Math.sqrt(determinant)) / (2 * a)
root2 = (-b - Math.sqrt(determinant)) / (2 * a)
output = "root1 = %.2f and root2 = %.2f".format(root1, root2)
}
// Condition for real and equal roots
else if (determinant == 0.0) {
root2 = -b / (2 * a)
root1 = root2
output = "root1 = root2 = %.2f;".format(root1)
}
// If roots are not real
else {
val realPart = -b / (2 * a)
val imaginaryPart = Math.sqrt(-determinant) / (2 * a)
output = "root1 = %.2f+%.2fi and root2 = %.2f-%.2fi".format(realPart, imaginaryPart, realPart, imaginaryPart)
}
println(output)
}