Sorry if I'm in the incorrect forum, but I'm new here :) I would need a function "multiplication" which returns the product of her parametres "a" and "b". Can anybody help me please?

on 2017-03-13 10:44

on 2017-03-13 11:40

Mi Gatt wrote in post #1185675: > Sorry if I'm in the incorrect forum, but I'm new here :) > > I would need a function "multiplication" which returns the product of > her parametres "a" and "b". > > Can anybody help me please? def mult(a,b) res=0 while true return(res) if b<=0 res=res+a b=b-1 end end p mult 7,7

on 2017-03-13 13:10

def add(a,b) sa='-'*a sb='-'*b return "#{sa}#{sb}".size end

on 2017-03-14 07:01

Regis d'Aubarede wrote in post #1185677: > def add(a,b) > sa='-'*a > sb='-'*b > return "#{sa}#{sb}".size > end Ah, I *love* this. This is by far the best answer to the question.

on 2017-03-17 12:33

```
Ronald Fischer wrote in post #1185684:
> Ah, I *love* this. This is by far the best answer to the question.
==
def n(a) '-'*a end
def s(a) a.size end
def add(a,b) return "#{a}#{b}" end
def moin(a,b) return a[0..-s(add(b,'-'))] end
def mult(a,b)
res=''
loop {
return(res) if b==''
res =add(a,res)
b=moin(b,'-')
}
end
p s( add('----','--') )
p s( add n(22), n(33) )
p s( moin n(22), n(1) )
p s( moin n(22), n(23) )
p s( mult n(3) , n(5) )
```