+ 2

Prime Palindrome Numbers.

Write a program to check whether a number is positive Prime Palindrome number or not. https://code.sololearn.com/c36wb799F7qy/?ref=app

16th Mar 2022, 7:26 PM
Md Saif Ali
Md Saif Ali - avatar
7 odpowiedzi
+ 5
No. it printing "all primes polindrome for any prime number. Do you checked for 127, 131 inputs...? By the way, without using coutdigits function and others extra variable, you can do simply int toReverse(int a) { int size=0,store=a,rev=0,c; while(store!=0) { c=store%10; rev=rev*10+c; store/=10; } return rev==a ? 1 : 0; } This way you can return 1 or 0 either you can return a reversed numbernumber, compare it in calling statement like I posted previously... Your way always results to even if it not polindrome ... hope it helps..
16th Mar 2022, 7:49 PM
Jayakrishna 🇮🇳
+ 3
if( isPrime(num) && (num == toReverse(num)))
16th Mar 2022, 7:34 PM
Jayakrishna 🇮🇳
+ 2
Saif ali , is there any issue with your code, do you have any question?
16th Mar 2022, 7:32 PM
Lothar
Lothar - avatar
+ 2
Lothar I wanna minimize this program as short as possible. 1) Is their any way by which I can directly find number of digits of a number? 2) I wanna try Boolean as return type but I am not able to get it right as I used to do in Java. 3) can we use ternary operators in C like '? ' and ':'
16th Mar 2022, 7:35 PM
Md Saif Ali
Md Saif Ali - avatar
+ 1
Jayakrishna🇮🇳 I don't think so what u r saying is correct. Actually the given code is correct, but I wanna minimize it
16th Mar 2022, 7:41 PM
Md Saif Ali
Md Saif Ali - avatar
+ 1
I like it more this way: doing reverse first, then prime, before SoloLearn timeout it runs to 9280829 swapping to check prime first, then check palindrome only gets to 1883881 https://code.sololearn.com/cBK5MefZPKK9/?ref=app
17th Mar 2022, 12:53 AM
HungryTradie
HungryTradie - avatar
0
// hope this link helps you https://code.sololearn.com/cn7bc0Uk3evY
17th Mar 2022, 12:49 AM
SoloProg
SoloProg - avatar