forked from SourceFusionHub/program
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Sandesh Kumar <[email protected]>
- Loading branch information
1 parent
02ac1ba
commit d1e6028
Showing
1 changed file
with
18 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,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() |