Skip to content

Commit

Permalink
Create 3KNbaL.swift
Browse files Browse the repository at this point in the history
Signed-off-by: Sandesh Kumar <[email protected]>
  • Loading branch information
I-sandesh authored and CodingWithHardik committed Oct 3, 2023
1 parent 02ac1ba commit d1e6028
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions ppSSDp/3KNbaL.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation
func average(_ a: Double, _ b: Double, _ c: Double) -> Double {
let sum = a + b + c
return sum / 3.0
}

func main() {
print("Please enter three numbers separated by spaces:")
let input = readLine()
let numbers = input?.split(separator: " ").map { Double($0) ?? 0.0 }
if let numbers = numbers, numbers.count == 3 {
let result = average(numbers[0], numbers[1], numbers[2])
print("The average of \(numbers[0]), \(numbers[1]), and \(numbers[2]) is \(result)")
} else {
print("Invalid input. Please enter exactly three numbers.")
}
}
main()

0 comments on commit d1e6028

Please sign in to comment.