+ 1

Palindromic Headache 🤕🤕

Please someone should help explain to me how this code block to check whether a number is palindromic works. Thanks. do { digit = num % 10; rev = (rev * 10) + digit; num = num / 10; } while (num != 0);

13th Dec 2022, 8:01 PM
DevAbdul
DevAbdul - avatar
3 ответов
+ 3
this example will explain #include <iostream> #include <conio.h> using namespace std; int main() { int num=15634; int digt=0; int rev=0; do{ //first loop digt =num%10; //digt=4 rev=(rev*10)+digt; //0+4=4 num=num/10; //num=1563 loop will continue /* //second loop loop will continue digt =num%10; //digt=3 rev=(rev*10)+digt; //40+3=43 num=num/10; //num=156 loop will continue //third loop digt =num%10; //digt=6 rev=(rev*10)+digt; //430+6=436 num=num/10; //num=15 loop will continue and so on; until loop finished the rev will be 43651 and it's not palindromic */ } while (num!=0) cout <<" number is :"<<rev<<endl; return 0; }
13th Dec 2022, 9:11 PM
Sultan Khalid
Sultan Khalid - avatar
+ 2
DevAbdul Here's is another example which may help: https://code.sololearn.com/ceN1PeIF7RBb/?ref=app
13th Dec 2022, 11:02 PM
Scott D
Scott D - avatar
0
Thanks for your help, I really appreciate it.
14th Dec 2022, 10:29 AM
DevAbdul
DevAbdul - avatar