+ 8

C language

This code should prints all the palindrome numbers which can be formed by multiplying two digits number.. I am not able to find out the bug in code. Code below đŸ‘‡đŸ»đŸ‘‡đŸ» https://code.sololearn.com/c68oSO8liY1l/?ref=app

26th Apr 2019, 4:28 PM
Night_fury~
Night_fury~ - avatar
4 Respostas
+ 7
#include<stdio.h> int main() { int p, num, rev = 0, rem; int n = 1; for(int a = 2; a < 20; a++) { for(int b = 2; b < 20; b++) { p = a * b; num = p; rev = 0; while( num > 0 ) { rem = num % 10 ; rev = rev * 10 + rem ; num /= 10 ; } if(p == rev) { printf("%d. palindrome = %d\n", n, p); n++; } } } return 0; } Corrected the code, you need to initialize rev to 0 after each termination of while loop.
26th Apr 2019, 7:34 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 6
It worked, thank you very much ~ swim ~ nAutAxH AhmAd
27th Apr 2019, 1:23 AM
Night_fury~
Night_fury~ - avatar
+ 6
But why do we have to initialize rev=0, I mean how does it matter. Value of rev will b changed after each iteration. đŸ€”đŸ§
27th Apr 2019, 1:26 AM
Night_fury~
Night_fury~ - avatar
+ 6
umm yep right.. thanks đŸ€© ~ swim ~
27th Apr 2019, 1:48 AM
Night_fury~
Night_fury~ - avatar