g | x | w | all
Bytes Lang Time Link
030Swift 6250501T153428ZmacOSist
038Tcl170528T185732Zsergiol
030Janet250430T173825Zxigoi
004Itr230812T171615Zbsoelch
002Thunno 2 S230809T182557ZThe Thon
047Scala230429T074650Z138 Aspe
017><>221217T190705ZEmigna
003Pyt221217T014558ZKip the
016Juby221215T213315ZJordan
015Raku221115T225712ZSean
009J221115T223514Zsouth
005MATL170528T143416ZSuever
018HP 28S210720T144528ZCount Ib
016Desmos210602T171013ZUndersla
028Excel 2016210518T175609ZAxuary
012Ly210518T041551Zcnamejj
006Pip210518T035015ZDLosc
003Vyxal210518T011905ZUndersla
017GolfScript201012T175531Z2014MELO
036Rust201012T162259ZAiden4
003Husk201012T064000ZRazetime
008Gol><>180503T073915ZBubbler
003Japt x170528T105554ZShaggy
020Braingolf170530T092142ZMayube
013QBIC170530T083026Zsteenber
035C gcc170530T072109ZGiacomo
006Brachylog170529T094752ZFatalize
021Haskell170529T085235ZUri Gore
003Jelly170528T102004ZErik the
011CJam170528T103238ZErik the
00305AB1E170528T103455ZErik the
005Pyth170528T103809ZErik the
054C170528T201834ZUriel
038Tcl170528T194848Zavl42
016Mathematica170528T101650ZZaMoC
034Axiom170528T112511Zuser5898
018JavaScript170528T104022Zuser4180
010CJam170528T114809ZLuis Men
015R170528T153051ZNitrodon
020Haskell170528T145640ZRyan McC
018Pari/GP170528T101717Zalephalp
005APL Dyalog170528T101725Zuser4180
033PHP170528T103823ZJör
027Python 3170528T103213Zshooqie

Swift 6, 30 bytes

let h={$0<1.0 ?0:1/$0+h($0-1)}

Try it on SwiftFiddle!

Tcl, 38 bytes

proc h x {expr $x?1./$x+\[h ($x-1)]:0}

Try it online!


# [Tcl], 50 bytes
proc h x {time {append s +1./[incr i]} $x;expr $s}

Try it online!

Janet, 30 bytes

|(sum(seq[i :down[$ 0]](/ i)))

Itr, 4 bytes

#¹¯S

outputs result as fraction

online interpreter

append 0e* for floating point output

Explanation

#    ; read number from stdin
 ¹   ; 1-based range
  ¯  ; replace elements with their reciprocals 
   S ; sum
     ; implicit output

Thunno 2 S, 2 bytes

RỊ

Try it online!

Explanation

RỊ  # Implicit input
R   # One range
 Ị  # Reciprocal
    # Take the sum
    # Implicit output

Scala, 47 bytes

Try it online!

def h(n:Int):Double=if(n==0)0 else 1.0/n+h(n-1)

><>, 17 bytes

0$:@?!n$:1-}1$,+!

Try it online!

Pyt, 3 bytes

ř⅟Ʃ
        implicit input
ř       produces a list containing 1 to n
 ⅟      takes the reciprocals
  Ʃ     sums the list
        (implicit print)

Try it online!

J-uby, 16 bytes

:+|:sum+(:/&1.0)

Attempt This Online!

Raku, 15 bytes

{sum 1 X/1..$_}

Try it online!

1 X/ 1..$_ is 1 cross-divided by the numbers from 1 up to the input number $_, producing the list 1, 1/2, 1/3, ..., 1/$_. Then (of course) sum sums them.

J, 9 bytes

1#.1%1+i.

I'm only posting this because I think it looks really pretty.

Attempt This Online!

1#.1%1+i.
       i.  NB. range 0..n-1
     1+    NB. add 1
   1%      NB. 1 divided by each element
1#.        NB. sum the result

MATL, 5 bytes

:l_^s

This solution uses 1-based indexing.

Try it at MATL Online

Explanation

    % Implicitly grab input (N)
:   % Create an array from [1...N]
l_^ % Raise all elements to the -1 power (take the inverse of each)
s   % Sum all values in the array and implicitly display the result

HP 28S, 18 bytes

0 1 ROT FOR K K INV + NEXT

Desmos, 16 bytes

total(1/[1...n])

Try it on desmos!

Uses the total function instead of sigma notation to be able to shave off the latex. Also uses desmos's built-in vectorization.

Excel (2016), 28 bytes

=SUM(1/ROW(OFFSET(A1,,,A1)))

Excel (current), 20 bytes

=SUM(1/SEQUENCE(A1))

Ly, 14 12 bytes

n[:1f/f1-]&+

Try it online!

Found a simpler way to do this... The original was: 0ns[1f/+l1-s]p

And here's what it's doing.

n

Get 'n' from the challenge (the number of iterations) from the input and push onto the stack.

[...]

As long as the top of the stack is non-zero.

:1f/

Duplicate the top of the stack (the iteration counter), and compute 1/n.

f1-

Flip the two entries on the stack so that the 1/n calculation is second and the iteration counter is on the top. Then decrement the iteration counter.

&+

Once all the values have been computed, sum the stack and print.

Pip, 6 bytes

$+/\,a

Try it online!

Explanation

     a  First command-line argument
   \,   Inclusive range from 1 through that number
  /     Invert each number in the range
$+      Fold on + (summing the list)
        Autoprint (implicit)

Vyxal, 3 bytes

ɾĖ∑

Lame answer, but range -> reciprocal -> sum -> implicit out, same as jelly

Try it Online!

Vyxal s, 2 bytes

ɾĖ

2 Bytes w/ -s from @lyxal, -s sums the stack

Try it Online!

GolfScript, 17 bytes

~),{2.-1??./\/+}*

Try it online!

1-indexed

~                   # Parse n to an integer
 ),                 # Make an array from 0 to n
   {           }*   # For each number in the array, skipping the 0
    2.-1??          # 2^(2^-1) = sqrt( 2 )  We just need any float
          ./        # Divide previous number by itself, this will result in the float 1.0
            \/      # Divide 1.0 by the current number of the array
              +     # Add the result

Without the convertion to float it could be reduced to 10 bytes, but the output would be a fraction.

~),{-1?+}*

Try it online!

Rust, 36 bytes

|n|(1..=n).map(|n|1./n as f64).sum()

Try it online!

Input is an integer, if the input is <=0 the output is zero, and inputting one gets one.

Husk, 3 bytes

ṁ\ḣ

Try it online!

Output is a fraction.

Gol><>, 8 bytes

F1LP,+|B

Try it online!

Example full program & How it works

1AGIE;GN
F1LP,+|B

1AGIE;GN
1AG       Register row 1 as function G
   IE;    Take input as int, halt if EOF
      GN  Call G and print the result as number
          Repeat indefinitely

F1LP,+|B
F     |   Repeat n times...
 1LP,       Compute 1 / (loop counter + 1)
     +      Add
       B  Return

Japt -x, 8 6 5 3 bytes

õpJ

With some thanks to ETHproductions

Try it online

Braingolf, 20 bytes [non-competing]

VR1-1[1,!/M,$_1+]v&+

This won't actually work due to braingolf's inability to work with floats, however the logic is correct.

Explanation:

VR1-1[1,!/M,$_1+]v&+   Implicit input
VR                     Create new stack and return to main stack
  1-                   Decrement input
    1                  Push 1
     [..........]      Loop, always runs once, then decrements first item on stack at ]
                       Breaks out of loop if first item on stack reaches 0
      1,!/             Push 1, swap last 2 values, and divide without popping
                       Original values are kept on stack, and result of division is pushed
          M,$_         Move result of division to next stack, then swap last 2 items and
                       Silently pop last item (1)
              1+       Increment last item on stack
                 v&+   Move to next stack, sum entire stack 
                       Implicit output of last item on current stack

Here's a modified interpreter that supports floats. First argument is input.

QBIC, 13 bytes

[:|c=c+1/a]?c

Explanation

[ |        FOR a = 1 to
 :            the input n
   c=c+    Add to c (starts off as 0)
   1/a     the reciprocal of the loop iterator
]          NEXT
?c         PRINT c

C (gcc), 35 bytes

float f(n){return n?1./n+f(--n):0;}

Try it online!

Brachylog, 6 bytes

⟦₁/₁ᵐ+

Try it online!

This is 1-indexed.

Explanation

⟦₁         Range [1, …, Input]
    ᵐ      Map:
  /₁         Inverse
     +     Sum

Haskell, 21 bytes

f n=sum$map(1/)[1..n]

Jelly, 3 bytes

İ€S

Try it online!

1-indexed.

Explanation:

İ€S Main link, monadic
İ€         1 / each one of [1..n]
  S Sum of

CJam, 11 bytes

1.ri,:)f/:+

Try it online!

1-indexed.

05AB1E, 3 bytes

LzO

Try it online!

1-indexed.

Pyth, 5 bytes

scL1S

Try it here.

1-indexed.

C, 54 bytes

i;float f(n){float s;for(i=n+1;--i;s+=1./i);return s;}

Uses 1-indexed numbers.

Tcl 38 bytes

proc h x {expr $x?1./($x)+\[h $x-1]:0}

That's a very dirty hack, and the recursive calls pass literal strings like "5-1-1-1..." until it evaluates to 0.

Mathematica, 21 20 16 bytes

This solution is 1-indexed.

Sum[1./i,{i,#}]&

Axiom, 45 34 bytes

f(x:PI):Any==sum(1./n,n=1..x)::Any

1-Indexed; It has argument one positive integer(PI) and return "Any" that the sys convert (or not convert) to the type useful for next function arg (at last it seems so seeing below examples)

(25) -> [[i,f(i)] for i in 1..9]
   (25)
   [[1,1.0], [2,1.5], [3,1.8333333333 333333333], [4,2.0833333333 333333333],
    [5,2.2833333333 333333333], [6,2.45], [7,2.5928571428 571428572],
    [8,2.7178571428 571428572], [9,2.8289682539 682539683]]
                                                      Type: List List Any
(26) -> f(3000)
   (26)  8.5837498899 591871142
                                        Type: Union(Expression Float,...)
(27) -> f(300000)
   (27)  13.1887550852 056117
                                        Type: Union(Expression Float,...)
(29) -> f(45)^2
   (29)  19.3155689383 88117644
                                                   Type: Expression Float

JavaScript, 19 18 bytes

1 byte saved thanks to @RickHitchcock

f=a=>a&&1/a+f(--a)

This is 1-indexed.

f=a=>a&&1/a+f(--a)

for(i=0;++i<10;)console.log(f(i))

CJam, 11 10 bytes

1 byte removed thanks to Erik the outgolfer

ri),{W#+}*

This uses 1-based indexing.

Try it online!

Explanation

ri            e# Read integer, n
  )           e# Increment by 1: gives n+1
   ,          e# Range: gives [0 1 2 ... n]
    {   }*    e# Fold this block over the array
     W#       e# Inverse of a number
       +      e# Add two numbers

R, 15 bytes

sum(1/1:scan())

Try it online!

Haskell, 20 bytes

f 0=0
f n=1/n+f(n-1)

Original solution, 22 bytes

f n=sum[1/k|k<-[1..n]]

These solutios assumes 1-indexed input.

Pari/GP, 18 bytes

n->sum(i=1,n,1./i)

1-indexing.

Try it online!

APL (Dyalog), 5 bytes

+/÷∘⍳

Try it online!

You can add ⎕PP←{number} to the header to change the precision to {number}.

This is 1-indexed.

Explanation

+/÷∘⍳                     Right argument; n
    ⍳                     Range; 1 2 ... n
  ÷                       Reciprocal; 1/1 1/2 ... 1/n
+/                        Sum; 1/1 + 1/2 + ... + 1/n

PHP, 33 Bytes

1-indexing

for(;$i++<$argn;)$s+=1/$i;echo$s;

Try it online!

Python 3, 27 bytes

h=lambda n:n and 1/n+h(n-1)