C=[3,4,5];
for i=2:n
C(end+1,1,1)=C(end,2,1);
C(end,2,1)=C(end-1,3,1);
C(end,3,1)=sqrt(C(end,1,1)^2+C(end,2,1)^2);
end
C= [C(end,:,1)]
area=C(3)^2
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
n = 1;
area_correct = 25;
tolerance = 1e-12;
assert(abs(triangle_sequence(n)-area_correct)<tolerance)
C =
3 4 5
area =
25
|
2 | Pass |
n = 2;
area_correct = 41;
tolerance = 1e-12;
assert(abs(triangle_sequence(n)-area_correct)<tolerance)
C =
4.0000 5.0000 6.4031
area =
41
|
3 | Pass |
n = 3;
area_correct = 66;
tolerance = 1e-12;
assert(abs(triangle_sequence(n)-area_correct)<tolerance)
C =
5.0000 6.4031 8.1240
area =
66.0000
|
4 | Pass |
n = 50;
area_correct = 439116598409;
tolerance = 1e-3;
assert(abs(triangle_sequence(n)-area_correct)<tolerance)
C =
1.0e+05 *
4.0955 5.2095 6.6266
area =
4.3912e+11
|
6063 Solvers
1309 Solvers
15295 Solvers
What is Sum Of all elements of Matrix
292 Solvers
Find the Oldest Person in a Room
5093 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!