- 3

palindromic number

A palindromic number is a number (such as 626) that remains the same when its digits are reversed. Write a function that returns true if a given number is a palindrome, and false, if it is not. Complete the given function, so that the code in main works and results in the expected output. Sample Input: 13431 Sample Output: 13431 is a palindrome

30th Jan 2021, 9:03 PM
Hazem_Alfayyad
Hazem_Alfayyad - avatar
21 Respostas
+ 53
#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ return true; } else{ return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
2nd Feb 2021, 12:49 PM
Mohammed Shaaz.K
Mohammed Shaaz.K - avatar
+ 3
Thank you very much🤗❤
30th Jan 2021, 9:17 PM
Hazem_Alfayyad
Hazem_Alfayyad - avatar
+ 2
#include <iostream> //#include <conio.h> using namespace std; int main() { int Input_Num; int Orignal_Num; int Reverse_Num; int Remainder=0; cin>>Input_Num; Orignal_Num=Input_Num; //int lengthCount = 0; for(; Input_Num != 0;) { Reverse_Num=Input_Num%10; Input_Num /= 10; Remainder=Remainder*10+Reverse_Num; Reverse_Num=Remainder; } if(Orignal_Num==Reverse_Num) { cout <<Orignal_Num<<" is a palindrome"; } else { cout <<Orignal_Num<<" is NOT a palindrome"; } return 0; }
27th Apr 2021, 1:02 AM
Premium World
+ 1
Unfortunately, I did not find the solution, so I shared the problem here so that someone can guide me to the solution, but I think I will use the "string" to cut or edit.
30th Jan 2021, 9:10 PM
Hazem_Alfayyad
Hazem_Alfayyad - avatar
+ 1
#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ return true; } else{ return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
29th Jul 2021, 6:52 AM
Panchasara Jayesh Prakashbhai
Panchasara Jayesh Prakashbhai - avatar
+ 1
#include <iostream> using namespace std; int revDigit(int y) { int rem,rev=0; while(y>0) { rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { if(x==revDigit(x)) { return true; } else{ return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
14th Aug 2021, 2:51 PM
Vraj Soni
Vraj Soni - avatar
+ 1
Let's break it down step by step: 1. `#include <iostream>`: This is a preprocessor directive that includes the iostream library which provides input and output stream functionality in C++. It allows the use of standard input and output operations like cout and cin. 2. `using namespace std;`: This line is used to avoid typing 'std::' before certain elements from the standard library such as cout and cin. By using the 'using namespace std;' statement you can directly use these elements without specifying the namespace. 3. `int revDigit(int y)`: This is the definition of a function named 'revDigit which takes an integer 'y' as a parameter and returns an integer. 4. `int rem rev = 0;`: This line declares two integer variables named 'rem' and 'rev and initializes 'rev' to 0. 5. `while (y > 0) { ... }`: This is a while loop that continues to execute the code inside the loop as long as the condition 'y > 0' is true. 6. Inside the while loop: - `rem = y % 10;`: This line calculates the remainder of 'y' when divided by 10 and assigns it to the 'rem' variable. - `rev = rev * 10 + rem;`: This line updates the 'rev' variable by appending the 'rem' value at the end. - `y /= 10;`: This line divides 'y' by 10 and assigns the result back to 'y effectively removing the last digit from 'y'. 7. After the while loop `return rev;` is used to return the final value of 'rev' from the 'revDigit' function. In summary the 'revDigit' function takes an integer as input and reverses its digits. For example if you pass 1234 to this function it will return 4321.
2nd Jul 2023, 2:41 AM
Avalon
Avalon - avatar
0
#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ return true; } else{ return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
12th Mar 2021, 4:00 PM
Dhaval Kanjariya
Dhaval Kanjariya - avatar
0
#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ return true; } else{ return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
15th Aug 2021, 2:26 AM
Phùng Châu Quốc
Phùng Châu Quốc - avatar
0
#include <iostream> using namespace std; int revdigit(int y){ int rem, rev=0; while(y>0){ rem = y%10; rev = rev*10+rem; y = y/10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revdigit(x)){ return true; } else{ return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
20th Aug 2021, 10:33 AM
Lahiru Thilakarathne
Lahiru Thilakarathne - avatar
0
#include <iostream> using namespace std; int revdigt(int z){ int digit,rev=0; while (z > 0) { digit = z % 10; rev = (rev * 10) + digit; z = z/ 10; } return rev; } bool isPalindrome(int x) { //complete the function if (x == revdigt(x)){ return true; } else{ return false; }} int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
25th Sep 2021, 5:05 AM
Muhammad Faisal
Muhammad Faisal - avatar
0
#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ return true; } else{ return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
6th Nov 2021, 4:33 PM
ashish Koshti
ashish Koshti - avatar
0
#include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int rev, val; val = x; while(x > 0){ rev = rev * 10 + x % 10; x = x / 10; } if (rev == val){ return true; } else return false; } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; } GOOGLE is your best friend in CODING!!
16th Nov 2021, 7:30 AM
Brian H
Brian H - avatar
0
#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ return true; } else{ return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; } Good Luck
13th Dec 2021, 2:26 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
0
Can someone explain to me how the entire code works please? This is how I understand it: starting from main() the isPalindrome(n) function is called passing the n variable (input) to that function. Then within that function does variable n become x within the isPalindrome function? Then x is compared to revDigit while also calling the revDigit function? I want to make sure I understand this correctly, Thank you!
26th Jan 2022, 3:10 PM
Green Tea
Green Tea - avatar
0
#include <iostream> using namespace std; int revDigit(int y){ int rem,rev=0; while(y>0){ rem=y%10; rev=rev*10+rem; y/=10; }return rev; } bool isPalindrome(int x) { //complete the function if(x==revDigit(x)){ return true; } else{ return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
15th Jun 2022, 12:35 AM
Abdelkhalek Nael Ahmad Allan
Abdelkhalek Nael Ahmad Allan - avatar
0
#include <iostream> using namespace std; int revers(int y){ int rev=0 , number; while(y>0){ rev*=10; number=y%10; rev+=number; y/=10; } return rev; } bool isPalindrome(int x) { //complete the function if(x==revers(x)){ return true; } else { return false; } } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
26th Sep 2022, 4:04 PM
Kimsinh Seang
Kimsinh Seang - avatar
0
#include <algorithm> #include<iostream> #include<string> using namespace std; int main() { string str, temp, str2; getline (cin, str); str2=str; reverse(str.begin(), str.end()); temp=str; temp.insert(temp.end(),' '); int n = temp.length(); int j = 0; for (int i = 0; i < n; i++) { if (temp[i] == ' ') { reverse(temp.begin() + j, temp.begin() + i); j = i + 1; } } reverse(temp.begin(), temp.end()); if(str==str2) { cout <<str2<<" is a palindrome"; } else { cout << str2<<" is NOT a palindrome"; } return 0; }
28th Oct 2022, 9:45 AM
Zendy Shervyl Fullido
0
took a while to figure it out... #include <iostream> using namespace std; bool isPalindrome(int x) { //complete the function int backward; if (x != 0 && x % 10 == 0 || x < 0) return false; while(x > backward){ backward = backward * 10 + x % 10; x = x / 10; } if(x == backward) { return true; } if(x == backward / 10) { return true; } return false; } int main() { int n; cin >>n; if(isPalindrome(n)) { cout <<n<<" is a palindrome"; } else { cout << n<<" is NOT a palindrome"; } return 0; }
27th Dec 2022, 12:28 PM
SERHII K
SERHII K - avatar
- 1
hello guys your code it's doesn't works because 8888 is not palindrome but i right in number 1 and 5,6
15th Aug 2021, 1:33 AM
kumarayana