Partage de codes sources - CodesWall.info
C
> Calcul euler (test)
Titre
Calcul euler (test)
Postée le
09-02-2011
Affichée
204
Mini-lien
Description
euler (test)
Etat
Ne contient pas d'erreurs.
Code d'insertion
Options
Tweet
Téléchargement
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
double
suite
(
)
;
double
arrondir
(
)
;
int
main
(
int
argc
,
char
**
argv
)
{
int
n
;
double
sn
,
val
;
n
=
atoi
(
argv
[
1
]
)
;
/* récuperation du paramètre n donné en argument */
printf
(
"n=%d
\n
"
,
n
)
;
sn
=
suite
(
n
-
1
)
;
/* calcul de s(n-1) */
val
=
arrondir
(
sn
-
log
(
n
)
,
n
)
;
/* on arrondie v(n)=s(n-1)-ln(n) à 1/n */
if
(
sn
-
log
(
n
)
>
val
)
/* on recupere la seule valeur comprise en v(n) et u(n) à 1/n près */
val
+=
(
double
)
1
/
n
;
printf
(
"%.10f << constante calculee
\n
"
,
val
)
;
printf
(
"0,5772156649015328606065120 << constante sur wikipedia
\n
"
)
;
return
0
;
}
double
suite
(
int
n
)
{
int
i
;
double
sn
=
0
;
if
(
n
==
0
)
return
0
;
for
(
i
=
1
;
i
<=
n
;
++
i
)
sn
+=
(
double
)
1
/
i
;
return
sn
;
}
double
arrondir
(
double
val
,
int
n
)
{
/* pour arrondir un nombre à 1/n */
val
*=
n
;
val
=
round
(
val
)
;
val
/=
n
;
return
val
;
}
/*
EXEMPLE DE SORTIES :
>> euler.exe 10000
n=10000
0.5772000000 << constante calculee
0,5772156649015328606065120 << constante sur wikipedia
>> euler.exe 1000000000
[sortie]
n=1000000000
0.5772156650 << constante calculee
0,5772156649015328606065120 << constante sur wikipedia
TEMPS D'EXECUTION :
n=10^4 -> 0.016s
n=10^9 -> 8.978s
*/
Postez votre code-source
Informations
Catégorie *
-
ActionScript3
ASP
C
C#.Net
C++
COBOL
CSS
Delphi
Fichier .ini
HTML4
HTML5
Java
javascript
jQuery
Latex
MatLab
mIRC
MySQL
Objective-C
OCaml
pascal
Perl
Php
Python
QBasic
Ruby
Script Batch
Shell
SmallTalk
VB.Net
VBA
Visual Basic
XML
Autre
Titre *
(50 car. max)
Description *
(200 car. max)
Le code
Fonctionne
Ne fonctionne pas
Je ne sais pas
Source
* : Champs obligatoires
Fermer
Accueil
Poster
Actualités
Règles
Contact
Partenaires
Infos / Aide
ActionScript3
(0)
ASP
(0)
C
(65)
C#.Net
(4)
C++
(51)
COBOL
(0)
CSS
(21)
Delphi
(0)
Fichier .ini
(5)
HTML4
(16)
HTML5
(2)
Java
(48)
javascript
(35)
jQuery
(0)
Latex
(6)
MatLab
(3)
mIRC
(3)
MySQL
(13)
Objective-C
(1)
OCaml
(4)
pascal
(9)
Perl
(11)
Php
(58)
Python
(3)
QBasic
(1)
Ruby
(1)
Script Batch
(8)
Shell
(10)
SmallTalk
(1)
VB.Net
(5)
VBA
(5)
Visual Basic
(6)
XML
(17)
Autre
(18)
\n
Forum informatique