Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PREMIERE
ALGO
algorithme
Commits
34d6c0f9
Commit
34d6c0f9
authored
Oct 25, 2021
by
Jonas
Browse files
Added factorial
parent
350c8106
Changes
4
Hide whitespace changes
Inline
Side-by-side
jmaths/bin/main
View file @
34d6c0f9
No preview for this file type
jmaths/include/jmath.h
View file @
34d6c0f9
...
...
@@ -24,5 +24,6 @@
uint64_t
GCD
(
uint64_t
a
,
uint64_t
b
);
uint64_t
LCM
(
uint64_t
a
,
uint64_t
b
);
bool
isPrime
(
uint64_t
n
);
uint64_t
fact
(
uint64_t
n
);
#endif
\ No newline at end of file
jmaths/src/jmath.c
View file @
34d6c0f9
...
...
@@ -65,6 +65,21 @@ bool isPrime(uint64_t n)
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
;
}
jmaths/src/main.c
View file @
34d6c0f9
...
...
@@ -23,6 +23,16 @@ int main()
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
t
=
clock
();
r
=
GCD
(
a
,
b
);
...
...
@@ -31,7 +41,6 @@ int main()
printf
(
"COMPUTED PGCD IN %lfs
\n
"
,
timeT
);
printf
(
"PGCD(%ld, %ld) = %ld
\n
"
,
a
,
b
,
r
);
// PPCM
t
=
clock
();
r
=
LCM
(
a
,
b
);
...
...
@@ -40,15 +49,13 @@ int main()
printf
(
"COMPUTED PPCM IN %lfs
\n
"
,
timeT
);
printf
(
"PPCM(%ld, %ld) = %ld
\n
"
,
a
,
b
,
r
);
//
PRIME
//
FACTORIAL
t
=
clock
();
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
printf
(
"%d is %s
\n
"
,
i
,
isPrime
(
i
)
?
"Prime"
:
"Not Prime"
);
}
r
=
fact
(
a
);
t
=
clock
()
-
t
;
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
;
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment