Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
495 B
3
Indexable
Never
// 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;
    }
}