Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
ICC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor 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
Show more breadcrumbs
Vytor Calixto
ICC
Commits
cb99f2f5
Commit
cb99f2f5
authored
9 years ago
by
Vytor Calixto
Browse files
Options
Downloads
Patches
Plain Diff
Lista 3
parent
242164a0
Branches
master
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lista3/ci164-Exercicios-03.pdf
+0
-0
0 additions, 0 deletions
lista3/ci164-Exercicios-03.pdf
lista3/ex4.c
+107
-0
107 additions, 0 deletions
lista3/ex4.c
with
107 additions
and
0 deletions
lista3/ci164-Exercicios-03.pdf
0 → 100644
+
0
−
0
View file @
cb99f2f5
File added
This diff is collapsed.
Click to expand it.
lista3/ex4.c
0 → 100644
+
107
−
0
View file @
cb99f2f5
#include
<stdio.h>
#include
<stdlib.h>
void
eliminaGauss
(
double
**
a
,
int
n
,
double
*
b
)
{
for
(
int
k
=
0
;
k
<
n
;
++
k
)
{
for
(
int
i
=
k
+
1
;
i
<
n
;
++
i
)
{
double
m
=
a
[
i
][
k
]
/
a
[
k
][
k
];
a
[
i
][
k
]
=
0
.
0
f
;
for
(
int
j
=
k
+
1
;
j
<
n
;
++
j
)
{
a
[
i
][
j
]
-=
a
[
k
][
j
]
*
m
;
}
b
[
i
]
-=
b
[
k
]
*
m
;
}
}
}
void
eliminaGaussPivo
(
double
**
a
,
int
n
,
double
*
b
)
{
for
(
int
k
=
0
;
k
<
n
;
++
k
)
{
int
max
=
k
;
for
(
int
i
=
k
+
1
;
i
<
n
;
++
i
)
{
max
=
(
a
[
i
][
k
]
>
a
[
max
][
k
])
?
i
:
max
;
}
if
(
max
!=
k
)
trocaLinha
(
a
,
n
,
b
,
max
,
k
);
for
(
int
i
=
k
+
1
;
i
<
n
;
++
i
)
{
double
m
=
a
[
i
][
k
]
/
a
[
k
][
k
];
a
[
i
][
k
]
=
0
.
0
f
;
for
(
int
j
=
k
+
1
;
j
<
n
;
++
j
)
{
a
[
i
][
j
]
-=
a
[
k
][
j
]
*
m
;
}
b
[
i
]
-=
b
[
k
]
*
m
;
}
}
}
void
trocaLinha
(
double
**
a
,
int
n
,
double
*
b
,
int
l1
,
int
l2
)
{
double
temp
;
temp
=
b
[
l2
];
b
[
l2
]
=
b
[
l1
];
b
[
l1
]
=
temp
;
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
temp
=
a
[
l1
][
i
];
a
[
l1
][
i
]
=
a
[
l2
][
i
];
a
[
l2
][
i
]
=
temp
;
}
}
void
retro
(
double
**
a
,
int
n
,
double
*
b
,
double
*
x
)
{
x
[
n
-
1
]
=
b
[
n
-
1
]
/
a
[
n
-
1
][
n
-
1
];
for
(
int
i
=
n
-
2
;
i
>=
0
;
--
i
)
{
double
soma
=
0
.
0
f
;
for
(
int
j
=
n
-
1
;
j
>
i
;
--
j
)
{
soma
+=
a
[
i
][
j
]
*
x
[
j
];
}
x
[
i
]
=
(
b
[
i
]
-
soma
)
/
a
[
i
][
i
];
}
}
int
main
()
{
double
**
a
,
**
A
,
*
b
,
*
B
,
*
x
;
int
n
;
printf
(
"Ordem da matriz:
\n
"
);
scanf
(
"%d"
,
&
n
);
a
=
malloc
(
n
*
sizeof
(
double
*
));
A
=
malloc
(
n
*
sizeof
(
double
*
));
b
=
malloc
(
n
*
sizeof
(
double
));
B
=
malloc
(
n
*
sizeof
(
double
));
x
=
malloc
(
n
*
sizeof
(
double
));
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
a
[
i
]
=
malloc
(
n
*
sizeof
(
double
));
A
[
i
]
=
malloc
(
n
*
sizeof
(
double
));
}
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
for
(
int
j
=
0
;
j
<
n
;
++
j
)
{
printf
(
"(%d, %d)
\t
"
,
i
,
j
);
scanf
(
"%lf"
,
&
a
[
i
][
j
]);
A
[
i
][
j
]
=
a
[
i
][
j
];
}
}
printf
(
"B
\n
"
);
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
printf
(
"b[%d]"
,
i
);
scanf
(
"%lf"
,
&
b
[
i
]);
B
[
i
]
=
b
[
i
];
}
eliminaGauss
(
a
,
n
,
b
);
retro
(
a
,
n
,
b
,
x
);
printf
(
"Resposta:
\n
"
);
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
printf
(
"%.4lf
\n
"
,
x
[
i
]);
}
eliminaGaussPivo
(
A
,
n
,
B
);
retro
(
A
,
n
,
B
,
x
);
printf
(
"Pivo:
\n
"
);
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
printf
(
"%.4lf
\n
"
,
x
[
i
]);
}
return
0
;
}
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