AD's_project1

AD's_project1 - student project

/*

The program  compute the values of the sum of

(1 + 1/2 + 1/3 + 1/4 + ... + 1/n) - ln(n) (ln is a natural logarithm)

for 100

f(100), f(200), f(300), ... (f1000)

*/

#include
#include

// fct qui calcul de 1+(1/2)+...+(1/n)

float sum1(int n )
{
    float s=0 ;
    int i ;
    for(i=1;i        s+=(1/i) ;
    }
    return s ;
}

/*
fct qui calcul (approx.) -ln(x)
j ai utilisé le d.l de ln(1-x)= - (1/1*x^1 + 1/2*x^2 + ... + 1/n*x^n )
avec un ptit changement de variable y=1-x j ai bien :
ln(y)= - (1/1*(1-y)^1 + 1/2*(1-y)^2 + ... + 1/n*(1-y)^n ) et par suite :
-ln(y)= 1/1*(1-y)^1 + 1/2*(1-y)^2 + ... + 1/n*(1-y)^n
           ****anglais****
fct that calculate -ln(x)
i used l.d for ln(1-x)= - (1/1*x^1 + 1/2*x^2 + ... + 1/n*x^n )
*/

float ln(int n)
{

    float r1 ,r2,s=0;
    int i=1 ;
    
    do{
    r1=(float)(1/i)*pow(1-n,i);
    s+=r1 ;
    i++ ;
    r2=1/i*pow(1-n,i);
    } while(fabs(r1-r2)>=0.001)  ;
    
    return s ;
}


main(){
    int i=100 ;
        do{
        printf("f(%d)=%.2f\n",i,sum1(i)+ln(i)) ;
        i+=100 ;
    }while(i    
    getchar() ;    
}