Monday, 6 June 2016

Haskell: Generate multiplication table of a number

Prelude> let mulTable num = [(num, x, num * x) | x <- [1..10]]
Prelude> mulTable 10
[(10,1,10),(10,2,20),(10,3,30),(10,4,40),(10,5,50),(10,6,60),(10,7,70),(10,8,80),(10,9,90),(10,10,100)]
Prelude> 
Prelude> mulTable 19
[(19,1,19),(19,2,38),(19,3,57),(19,4,76),(19,5,95),(19,6,114),(19,7,133),(19,8,152),(19,9,171),(19,10,190)]

Previous                                                 Next                                                 Home

No comments:

Post a Comment