Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
TP IDM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coline LEDEZ
TP IDM
Commits
70d958a0
Commit
70d958a0
authored
Dec 25, 2023
by
Coline LEDEZ
Browse files
Options
Downloads
Patches
Plain Diff
question 4
parent
cef7541a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+7
-1
7 additions, 1 deletion
README.md
tp5.cpp
+0
-33
0 additions, 33 deletions
tp5.cpp
tp5_q4.cpp
+67
-0
67 additions, 0 deletions
tp5_q4.cpp
with
74 additions
and
34 deletions
README.md
+
7
−
1
View file @
70d958a0
...
...
@@ -12,9 +12,15 @@ Compiler la question 2 :
g++ ../tp5_q2.cpp -I./include ./lib/libCLHEP-Random-2.1.0.0.a -static -o tp5_q2
```
Compiler la question
2
:
Compiler la question
3
:
```
g++ ../tp5_q3.cpp -I./include ./lib/libCLHEP-Random-2.1.0.0.a -static -o tp5_q3
```
Compiler la question 4 :
```
g++ ../tp5_q4.cpp -I./include ./lib/libCLHEP-Random-2.1.0.0.a -static -o tp5_q4
```
This diff is collapsed.
Click to expand it.
tp5.cpp
deleted
100644 → 0
+
0
−
33
View file @
cef7541a
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<fcntl.h>
#include
<limits.h>
#include
<unistd.h>
#include
<string>
#include
"Random/CLHEP/Random/MTwistEngine.h"
int
main
()
{
CLHEP
::
MTwistEngine
*
mtRng
=
new
CLHEP
::
MTwistEngine
();
int
i
;
int
j
;
double
fRn
;
std
::
string
nom_fichier_base
=
"q2_status"
;
std
::
string
nom_fichier
=
""
;
for
(
i
=
0
;
i
<
5
;
i
++
)
{
for
(
j
=
0
;
j
<
10
;
j
++
)
{
fRn
=
mtRng
->
flat
();
}
nom_fichier
=
nom_fichier_base
+
std
::
to_string
(
i
);
mtRng
->
saveStatus
(
nom_fichier
.
c_str
());
}
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tp5_q4.cpp
0 → 100644
+
67
−
0
View file @
70d958a0
#include
<sys/types.h>
#include
<sys/stat.h>
#include
<fcntl.h>
#include
<limits.h>
#include
<unistd.h>
#include
<ctime>
#include
<string>
#include
"Random/CLHEP/Random/MTwistEngine.h"
int
main
()
{
int
tirage
=
1000000000
;
CLHEP
::
MTwistEngine
*
mtRng
=
new
CLHEP
::
MTwistEngine
();
int
i
;
int
j
;
float
x_alea
;
//Abscisse du point aléatoire
float
y_alea
;
//Ordonnée du point aléatoire
time_t
debut
,
fin
;
std
::
string
nom_fichier_base
=
"q3_status"
;
std
::
string
nom_fichier
=
""
;
time
(
&
debut
);
// Une simulation de pi
for
(
i
=
0
;
i
<
10
;
i
++
)
{
double
pi
=
0
;
nom_fichier
=
nom_fichier_base
+
std
::
to_string
(
i
);
mtRng
->
restoreStatus
(
nom_fichier
.
c_str
());
for
(
j
=
0
;
j
<
tirage
;
j
++
)
{
x_alea
=
(
mtRng
->
flat
()
-
0.5
)
*
2
;
//nombre entre 0 et 1
y_alea
=
(
mtRng
->
flat
()
-
0.5
)
*
2
;
//-> entre -0.5 et 0.5
//-> entre -1 et 1
//Si la distance à l'origine <= 1, c'est-à-dire si le point
//est dans le cercle
if
(
x_alea
*
x_alea
+
y_alea
*
y_alea
<=
1
)
{
pi
+=
1
;
}
}
pi
/=
tirage
;
//proportion de l'aire du cercle par rapport à
//celle du carré
pi
*=
4
;
//Multiplié par l'aire du carré, donne l'aire du
//cercle, soit pi
std
::
cout
<<
"pi = "
<<
pi
<<
std
::
endl
;
}
time
(
&
fin
);
std
::
cout
<<
"temps d'exécution : "
<<
difftime
(
fin
,
debut
)
<<
std
::
endl
;
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment