-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ada0a6f
commit 239b62a
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |