Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitscript authored Sep 23, 2022
1 parent ada0a6f commit 239b62a
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions 11Day-Palindrome.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.5.0 <0.9.0;
//A palindrome number is a number that is same after reverse.For example 545, 151, 34543 etc.
contract Day5 {
//Create a function palindrome(uint n) . Thispalindrome() will check whether n is a palindrome or not.
function palindrome(uint256 n) public pure returns (uint256) {
uint256 reversed = 0;
uint256 remainder;
uint256 original;

original = n;
while (n != 0) {
remainder = n % 10;
reversed = reversed * 10 + remainder;
n /= 10;
}
//If n is a palindrome then palindrome() returns 1 and n is not palindrome then palindrome() must return 0.
if (original == reversed) {
return 1; //palindrome
} else {
return 0; //not palindrome
}
}
}

0 comments on commit 239b62a

Please sign in to comment.