Untitled
unknown
plain_text
2 years ago
495 B
11
Indexable
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Fibonacci {
//To find the value of n+1 th Fibonacci number
function fibonacci(uint n) public pure returns (uint) {
if (n == 0) {
return 0;
}
uint256 a = 1;
uint256 b = 1;
for (uint256 i = 2; i < n;) {
uint c = a + b;
a = b;
b = c;
unchecked {
i = i+1;
}
}
return b;
}
}Editor is loading...