I can't deal with this code.Please help me:)

조회 수: 1 (최근 30일)
Mehdi Yetimçok
Mehdi Yetimçok 2021년 6월 8일
댓글: Walter Roberson 2023년 7월 8일
clear all;
close all;
clc;
n= input("Enter an number to calculate its fibonacci number: "))
F = [1 1]; % Initially F has two elements
for i = 1:(n-2);
F(end+1) = F(end-1) + F(end);
if n> 0:
disp("You entered a positive number.List every fibonacci number smaller or equal than the given number")
else n<0:
disp("You enteres a negative number.Please enter the positive one!")
end
  댓글 수: 1
Kishore
Kishore 2023년 7월 8일
clear all;
close all;
clc;
n= input("Enter an number to calculate its fibonacci number: ")
F = [1 1]; % Initially F has two elements
for i = 1:(n-2);
F(end+1) = F(end-1) + F(end);
if n> 0
disp("You entered a positive number.List every fibonacci number smaller or equal than the given number")
else n<0
disp("You enteres a negative number.Please enter the positive one!")
end
end

댓글을 달려면 로그인하십시오.

답변 (2개)

KSSV
KSSV 2021년 6월 8일

Kishore
Kishore 2023년 7월 8일
clear all;
close all;
clc;
n= input("Enter an number to calculate its fibonacci number: ")
F = [1 1]; % Initially F has two elements
for i = 1:(n-2);
F(end+1) = F(end-1) + F(end);
if n> 0
disp("You entered a positive number.List every fibonacci number smaller or equal than the given number")
else n<0
disp("You enteres a negative number.Please enter the positive one!")
end
end
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 7월 8일
If n is not at least 3, then the body of the for loop will not be executed, and so the test whether n<0 would not be executed.
The code also does not ensure that n is an integer.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by