+ 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
4 odpowiedzi
+ 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.
+ 6
It worked, thank you very much ~ swim ~ nAutAxH AhmAd
+ 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. 🤔🧐
+ 6
umm yep right.. thanks 🤩 ~ swim ~