Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
controle-c-001
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
florian.burgener
controle-c-001
Commits
d40041b1
Commit
d40041b1
authored
3 years ago
by
Florian Burgener
Browse files
Options
Downloads
Patches
Plain Diff
Validation exercice 3
parent
de6fb34d
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ex3/main.c
+21
-10
21 additions, 10 deletions
ex3/main.c
with
21 additions
and
10 deletions
ex3/main.c
+
21
−
10
View file @
d40041b1
/**
* @file main.c
* @author
Prénom Nom
* @brief Exercice
1
* @author
Florian Burgener
* @brief Exercice
3
* @version 1.0
* @date 2021-12-07
*
...
...
@@ -9,20 +9,28 @@
*
*/
#include
<math.h>
#include
<stdbool.h>
#include
<stdint.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<string.h>
/**
* @brief Count all the possibilities of dividing a sum of money into pieces of 2, 5 and 10.
*
* @param remaining_money
* @param available_money
* @return int32_t
*/
int32_t
count_posibilities
(
int32_t
remaining_money
,
int32_t
available_money
)
{
if
(
available_money
==
1
)
{
if
(
available_money
==
1
)
{
// No matter how much money is left, it is a possibility because you can have n * 1 pieces.
return
1
;
}
int32_t
next_available_money
=
available_money
;
// Determines which unit of money will be used for further calculations.
// 10 => 2
// 2 => 1
if
(
next_available_money
==
10
)
{
next_available_money
=
2
;
}
else
if
(
next_available_money
==
2
)
{
...
...
@@ -30,21 +38,24 @@ int32_t count_posibilities(int32_t remaining_money, int32_t available_money) {
}
int32_t
count
=
0
;
int32_t
i
=
1
;
int32_t
i
=
0
;
while
(
remaining_money
>=
i
*
available_money
)
{
// As long as the multiplication of i by the current money unit is smaller than or equal to the remaining money, continue to loop.
while
(
remaining_money
>=
i
*
available_money
)
{
// Calls back the function by withdrawing the right amount of money.
count
+=
count_posibilities
(
remaining_money
-
available_money
*
i
,
next_available_money
);
i
+=
1
;
}
count
+=
count_posibilities
(
remaining_money
,
next_available_money
);
return
count
;
}
int
main
()
{
int32_t
input
;
scanf
(
"%d"
,
&
input
);
int32_t
count
=
count_posibilities
(
input
,
10
);
printf
(
"
\n
%d
\n
"
,
count
);
return
EXIT_SUCCESS
;
}
\ 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