Calculate the sum of: 1 + 1/2 + 1/3 + 1/4 + . . . + 1/n
for “n” given terms.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <stdio.h>

float sum(int n){
    if(n==1)
        return 1;
    else
        return 1.0/n+sum(n-1);
}

int main(){
    int n;
   
    printf("Dwse n: ");
    scanf("%d",&n);

    printf("Sum: %f",sum(n));
   
    return 0;
}