Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
algorithme
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
PREMIERE
ALGO
algorithme
Commits
34d6c0f9
Commit
34d6c0f9
authored
Oct 25, 2021
by
Jonas
Browse files
Options
Downloads
Patches
Plain Diff
Added factorial
parent
350c8106
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
jmaths/bin/main
+0
-0
0 additions, 0 deletions
jmaths/bin/main
jmaths/include/jmath.h
+1
-0
1 addition, 0 deletions
jmaths/include/jmath.h
jmaths/src/jmath.c
+15
-0
15 additions, 0 deletions
jmaths/src/jmath.c
jmaths/src/main.c
+14
-7
14 additions, 7 deletions
jmaths/src/main.c
with
30 additions
and
7 deletions
jmaths/bin/main
+
0
−
0
View file @
34d6c0f9
No preview for this file type
This diff is collapsed.
Click to expand it.
jmaths/include/jmath.h
+
1
−
0
View file @
34d6c0f9
...
@@ -24,5 +24,6 @@
...
@@ -24,5 +24,6 @@
uint64_t
GCD
(
uint64_t
a
,
uint64_t
b
);
uint64_t
GCD
(
uint64_t
a
,
uint64_t
b
);
uint64_t
LCM
(
uint64_t
a
,
uint64_t
b
);
uint64_t
LCM
(
uint64_t
a
,
uint64_t
b
);
bool
isPrime
(
uint64_t
n
);
bool
isPrime
(
uint64_t
n
);
uint64_t
fact
(
uint64_t
n
);
#endif
#endif
\ No newline at end of file
This diff is collapsed.
Click to expand it.
jmaths/src/jmath.c
+
15
−
0
View file @
34d6c0f9
...
@@ -65,6 +65,21 @@ bool isPrime(uint64_t n)
...
@@ -65,6 +65,21 @@ bool isPrime(uint64_t n)
return
true
;
return
true
;
}
}
/**
* @brief Get the factorial of a number
*
* @param n
* @return uint64_t
*/
uint64_t
fact
(
uint64_t
n
)
{
uint64_t
r
=
1
;
for
(
uint64_t
i
=
2
;
i
<=
n
;
i
++
)
{
r
*=
i
;
}
return
r
;
}
This diff is collapsed.
Click to expand it.
jmaths/src/main.c
+
14
−
7
View file @
34d6c0f9
...
@@ -23,6 +23,16 @@ int main()
...
@@ -23,6 +23,16 @@ int main()
clock_t
t
;
clock_t
t
;
// PRIME
t
=
clock
();
for
(
int
i
=
0
;
i
<
10
;
i
++
)
{
printf
(
"%d is %s
\n
"
,
i
,
isPrime
(
i
)
?
"Prime"
:
"Not Prime"
);
}
t
=
clock
()
-
t
;
timeT
=
((
double
)
t
)
/
CLOCKS_PER_SEC
;
printf
(
"COMPUTED 10 NUMBERS FOR PRIMABILITY IN %lfms
\n
"
,
timeT
*
1000
);
// PGCD
// PGCD
t
=
clock
();
t
=
clock
();
r
=
GCD
(
a
,
b
);
r
=
GCD
(
a
,
b
);
...
@@ -31,7 +41,6 @@ int main()
...
@@ -31,7 +41,6 @@ int main()
printf
(
"COMPUTED PGCD IN %lfs
\n
"
,
timeT
);
printf
(
"COMPUTED PGCD IN %lfs
\n
"
,
timeT
);
printf
(
"PGCD(%ld, %ld) = %ld
\n
"
,
a
,
b
,
r
);
printf
(
"PGCD(%ld, %ld) = %ld
\n
"
,
a
,
b
,
r
);
// PPCM
// PPCM
t
=
clock
();
t
=
clock
();
r
=
LCM
(
a
,
b
);
r
=
LCM
(
a
,
b
);
...
@@ -40,15 +49,13 @@ int main()
...
@@ -40,15 +49,13 @@ int main()
printf
(
"COMPUTED PPCM IN %lfs
\n
"
,
timeT
);
printf
(
"COMPUTED PPCM IN %lfs
\n
"
,
timeT
);
printf
(
"PPCM(%ld, %ld) = %ld
\n
"
,
a
,
b
,
r
);
printf
(
"PPCM(%ld, %ld) = %ld
\n
"
,
a
,
b
,
r
);
//
PRIME
//
FACTORIAL
t
=
clock
();
t
=
clock
();
for
(
int
i
=
0
;
i
<
100
;
i
++
)
r
=
fact
(
a
);
{
printf
(
"%d is %s
\n
"
,
i
,
isPrime
(
i
)
?
"Prime"
:
"Not Prime"
);
}
t
=
clock
()
-
t
;
t
=
clock
()
-
t
;
timeT
=
((
double
)
t
)
/
CLOCKS_PER_SEC
;
timeT
=
((
double
)
t
)
/
CLOCKS_PER_SEC
;
printf
(
"COMPUTED 100 NUMBER FOR PRIMABILITY IN %lfms
\n
"
,
timeT
*
1000
);
printf
(
"COMPUTED FACTORIAL IN %lfs
\n
"
,
timeT
);
printf
(
"FACT(%ld) = %ld
\n
"
,
a
,
r
);
return
0
;
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
sign in
to comment