OneCompiler

bc sum

147

pragma solidity 0.8.22;

contract SumOfNaturalNumbers {
function sumOfN(uint n) public pure returns (uint) {
require(n > 0, "Input should be greater than 0");
return n * (n + 1) / 2;
}
}