Create a free account on Computer Sir Ki Class and unlock access to valuable learning resources.
Exam Paper Downloads: After registering and logging in, you can download exam question papers in PDF format to practice and prepare for your exams.
Student Support: Get assistance with your doubts, queries, and questions related to your studies. Our support is here to help you understand topics and resolve your learning difficulties.
Register today and make your exam preparation easier and more effective!
Related codes are those codes where similar programming concepts are in use. They are different from alternate codes in the sense that they may not have same purpose and results.
for(int n=1;n<=1000;++n) {
This is external loop to test every number from from 1 to 1000
int rem,nr=0; //rem initialised to collect remainder and nr is to get the reversed number int nc=n; //nc is to create copy of number so that it can be used for reseversal loop. This allowed to later compare n with nr for palindrome testing. If we do not run loop on nc, the value of n will become 0 due to very nature of reversal loop.
while(nc>0) {
This is internal loop to reverse the integer number n which is now save in nc
rem=nc%10; //Last digit is extracted which is remainder after division from 10 nr=nr*10+rem; //Previous number multiplied by 10 to shift it left and then added with Last digit. This will successive allow number reversal. nc=nc/10; } //Number is reduced by cutting the last digit so that whole number is processed digit by digit starting from the rightmost digit.
if(n==nr) cout<<n<<” “; //This tests if reversed number is same as original number and when same number is understood as a palindrome number so it is printed.
}