Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

very simple loop in F#

Tags:

f#

I tried this in both FSI and VS2010.Both gives the same output.

for i= 8 to 10 do
    for j=7 to 10 do
    let product=i*j
    printfn "%d * %o = %x" i j product

and the output is:

8*7=38
8*10=40
8*11=48
8*12=50
9*7=3f
9*10=48
9*11=51
9*12=5a
10*7=46
10*10=50
10*11=5a
10*12=64
val it : unit = ()

Am i missing something here?

I try to learn programming (with F# because I loved it) with online tutorials.

like image 540
mehmetselim Avatar asked Dec 31 '25 07:12

mehmetselim


2 Answers

The output seems correct to me, since you are formatting the output of i, j and product in decimal (%d), octal (%o) and hex (%x), respectively.

The numbers 7, 8, 9 and 10 are being formatted as 7, 10, 11, and 12 because that is their octal representation. Change them all to %d or %i to fix the problem.

like image 123
Richard Szalay Avatar answered Jan 02 '26 21:01

Richard Szalay


Yes. You're missing something. 10(decimal) * 10 (octal) = 50 (hex). %d means decimal, %o means octal, and %x means hexidecimal. If you don't know what they are, google them.

The following are all the same statement.

In decimal:

10 * 8 = 80.

in octal:

12 * 10 = 120

in hex:

a * 8 = 50.

Please look closely at something before you copy it.

like image 36
Kyle Butt Avatar answered Jan 02 '26 22:01

Kyle Butt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!