Finding sum of digits of a number until sum becomes single digit
Nov 26, 2020
Input : 1234
Output : 1
Explanation : The sum of 1+2+3+4 = 10,
digSum(x) == 10
Hence ans will be 1+0 = 1
import UIKit
class ViewController: UIViewController {
var digit = 1234
override func viewDidLoad() {
super.viewDidLoad()
let digits = digit % 9 == 0 ? 9 : digit % 9
print(digits)
// Do any additional setup after loading the view.
}
}