How to multiply two numbers without using the multiple operator (*) in Swift

1 Answer

0 votes
import Foundation

func mul() {
    let a = 3
    let b = 9
    var mul = 0

    // mul = a * b

    for _ in 1...a {
        mul += b
    }

    print("\(a) * \(b) = \(mul)")
}

mul()


 
/*
run:
 
3 * 9 = 27
 
*/

 



answered Dec 5, 2024 by avibootz
...