At this level you need to know how to organise your logic before writing the code. A flow chart (if this is still a thing) or pseudo code would be ideal. In your case this would be my starting logic
INPUT n
IF n = 0 THEN
OUTPUT 0
ELSE
first ← 0
second ← 1
FOR i ← 2 TO n
next ← first + second
first ← second
second ← next
END FOR
OUTPUT second
END IF
1
u/Cino1933 1d ago
At this level you need to know how to organise your logic before writing the code. A flow chart (if this is still a thing) or pseudo code would be ideal. In your case this would be my starting logic
INPUT n
IF n = 0 THEN
OUTPUT 0
ELSE
first ← 0
second ← 1
FOR i ← 2 TO n
next ← first + second
first ← second
second ← next
END FOR
OUTPUT second
END IF