Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
progseq-dynamic_memory_allocation
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
dario.genga
progseq-dynamic_memory_allocation
Commits
3b703fb8
Commit
3b703fb8
authored
3 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add method to multiply an array with a value
The value is given by the user.
parent
6163ed7f
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
histo.c
+11
-1
11 additions, 1 deletion
histo.c
unidimensional_array.c
+6
-0
6 additions, 0 deletions
unidimensional_array.c
unidimensional_array.h
+2
-0
2 additions, 0 deletions
unidimensional_array.h
with
19 additions
and
1 deletion
histo.c
+
11
−
1
View file @
3b703fb8
...
@@ -9,6 +9,7 @@ int main() {
...
@@ -9,6 +9,7 @@ int main() {
srand
(
time
(
NULL
));
srand
(
time
(
NULL
));
size_t
cycle_number
=
3
;
size_t
cycle_number
=
3
;
size_t
value
=
0
;
size_t
value
=
0
;
size_t
multiply_value
=
0
;
// Ask the user the size of the array
// Ask the user the size of the array
size_t
array_size
=
ask_array_size
();
size_t
array_size
=
ask_array_size
();
int
*
array
=
malloc
(
array_size
*
sizeof
(
int
));
int
*
array
=
malloc
(
array_size
*
sizeof
(
int
));
...
@@ -56,10 +57,19 @@ int main() {
...
@@ -56,10 +57,19 @@ int main() {
printf
(
"Result array :
\n
"
);
printf
(
"Result array :
\n
"
);
print_array
(
result_sum_array
,
array_size
);
print_array
(
result_sum_array
,
array_size
);
// Create a fourth array that will stock the multiplication between the first array and a value from the user
int
*
result_mul_array
=
malloc
(
array_size
*
sizeof
(
int
));
printf
(
"Multiply the first array with the following value :
\n
"
);
scanf
(
"%ld"
,
&
multiply_value
);
multiply_array_with_value
(
array
,
array_size
,
result_mul_array
,
multiply_value
);
printf
(
"Result array after multiplication :
\n
"
);
print_array
(
result_mul_array
,
array_size
);
// Free the memory
// Free the memory
free
(
array
);
free
(
array
);
free
(
second_array
);
free
(
second_array
);
free
(
result_array
);
free
(
result_sum_array
);
free
(
result_mul_array
);
return
0
;
return
0
;
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
unidimensional_array.c
+
6
−
0
View file @
3b703fb8
...
@@ -116,6 +116,12 @@ void compute_two_array(int* first_array, int* second_array, int* result_array, s
...
@@ -116,6 +116,12 @@ void compute_two_array(int* first_array, int* second_array, int* result_array, s
}
}
}
}
void
multiply_array_with_value
(
int
*
array
,
size_t
array_size
,
int
*
result_array
,
int
value
)
{
for
(
size_t
i
=
0
;
i
<
array_size
;
i
++
)
{
result_array
[
i
]
=
array
[
i
]
*
value
;
}
}
void
swap
(
int
*
x
,
int
*
y
)
void
swap
(
int
*
x
,
int
*
y
)
{
{
int
tmp
=
*
x
;
int
tmp
=
*
x
;
...
...
This diff is collapsed.
Click to expand it.
unidimensional_array.h
+
2
−
0
View file @
3b703fb8
...
@@ -25,6 +25,8 @@ size_t count_elements_in_array_lower_than_value(int* array, size_t array_size, i
...
@@ -25,6 +25,8 @@ size_t count_elements_in_array_lower_than_value(int* array, size_t array_size, i
void
compute_two_array
(
int
*
first_array
,
int
*
second_array
,
int
*
result_array
,
size_t
array_size
);
void
compute_two_array
(
int
*
first_array
,
int
*
second_array
,
int
*
result_array
,
size_t
array_size
);
void
multiply_array_with_value
(
int
*
array
,
size_t
array_size
,
int
*
result_array
,
int
value
);
void
print_array
(
int
*
array
,
size_t
array_size
);
void
print_array
(
int
*
array
,
size_t
array_size
);
void
swap
(
int
*
x
,
int
*
y
);
void
swap
(
int
*
x
,
int
*
y
);
...
...
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