Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
progseq-controle_continue_3
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-controle_continue_3
Commits
a5cd2dd1
Commit
a5cd2dd1
authored
2 years ago
by
dario.genga
Browse files
Options
Downloads
Patches
Plain Diff
Add finished ex1
parent
9cf596f4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ex1/ex1.c
+62
-0
62 additions, 0 deletions
ex1/ex1.c
with
62 additions
and
0 deletions
ex1/ex1.c
+
62
−
0
View file @
a5cd2dd1
...
...
@@ -7,7 +7,69 @@
#include
<stdlib.h>
#include
<string.h>
#include
<stdbool.h>
#include
<math.h>
double
**
alloc_matrix
(
int
nb_row
,
int
nb_col
)
{
double
**
matrix
=
malloc
(
sizeof
(
double
)
*
nb_row
);
for
(
int
i
=
0
;
i
<
nb_row
;
i
++
)
{
matrix
[
i
]
=
malloc
(
sizeof
(
double
)
*
nb_col
);
}
return
matrix
;
}
double
**
create_matrix
(
int
nb_row
,
int
nb_col
)
{
double
**
matrix
=
alloc_matrix
(
nb_row
,
nb_col
);
for
(
int
row
=
0
;
row
<
nb_row
;
row
++
)
{
for
(
int
col
=
0
;
col
<
nb_col
;
col
++
)
{
matrix
[
row
][
col
]
=
sqrt
(
row
+
col
);
}
}
return
matrix
;
}
double
**
average_matrix
(
double
**
matrix
,
int
nb_row
,
int
nb_col
)
{
double
**
average
=
alloc_matrix
(
nb_row
,
nb_col
);
for
(
int
row
=
0
;
row
<
nb_row
;
row
++
)
{
for
(
int
col
=
0
;
col
<
nb_col
;
col
++
)
{
double
ave
=
0
;
if
(
row
>=
1
&&
row
<=
nb_row
-
2
&&
col
>=
1
&&
col
<=
nb_col
-
2
)
{
ave
=
(
1
.
0
/
5
.
0
)
*
(
matrix
[
row
][
col
]
+
matrix
[
row
+
1
][
col
]
+
matrix
[
row
-
1
][
col
]
+
matrix
[
row
][
col
+
1
]
+
matrix
[
row
][
col
-
1
]);
}
else
{
ave
=
matrix
[
row
][
col
];
}
average
[
row
][
col
]
=
ave
;
}
}
return
average
;
}
void
destroy
(
double
**
matrix
,
int
nb_row
)
{
for
(
int
row
=
0
;
row
<
nb_row
;
row
++
)
{
free
(
matrix
[
row
]);
}
free
(
matrix
);
}
void
print_matrix
(
double
**
matrix
,
int
nb_row
,
int
nb_col
)
{
for
(
int
row
=
0
;
row
<
nb_row
;
row
++
)
{
for
(
int
col
=
0
;
col
<
nb_col
;
col
++
)
{
printf
(
"%f "
,
matrix
[
row
][
col
]);
}
printf
(
"
\n
"
);
}
}
int
main
()
{
int
row
=
5
;
int
col
=
4
;
double
**
matrix
=
create_matrix
(
row
,
col
);
double
**
average
=
average_matrix
(
matrix
,
row
,
col
);
print_matrix
(
average
,
row
,
col
);
destroy
(
matrix
,
row
);
destroy
(
average
,
row
);
return
EXIT_SUCCESS
;
}
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