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

1 Answer

0 votes
package main

import "fmt"

func multiply(a int, b int) int {
	mul := 0

	for i := 1; i <= a; i++ {
		mul = mul + b
	}

	return mul
}

func main() {
	a := 3
	b := 9

	fmt.Printf("%d * %d = %d\n", a, b, multiply(a, b))
}


/*
run:

3 * 9 = 27

*/

 



answered Aug 31, 2024 by avibootz
...