+ 1

Can you help me with this? Solve it in C

Write a program that finds the number of prime palindromic numbers between two given numbers: m and n. For example: If m and n are given : 10000 12000 Then the prime palindromic numbers are: 10301 10501 10601 11311 11411.

25th Jan 2019, 7:37 PM
eerv
eerv - avatar
10 odpowiedzi
+ 10
eerv Hello, 😊 Did you manage to do the assignment, are my instructions helps you? Do you need more help to work on?
26th Jan 2019, 10:08 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 9
eerv I see, you did not finishing the functions lesson (C tutorial)! For surely, there are even better and simpler solutions for this task. I did it using two functions to check whether the number is prime and palindrome: https://code.sololearn.com/c66d6Ub1SSg0/?ref=app
26th Jan 2019, 12:40 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 8
eerv To solve this problem, you can make two functions: #1st for checking whether the number is prime or not; #2nd for checking whether the number is palindrome or not. • Checking for palindrome, An integer is said to be a palindrome if it is equal to its reverse. For example, 79197 and 324423 are palindromes. int palindrome(int num){   int rev = 0;   int temp = num;   while (num > 0){     rev = rev * 10;     rev = rev + num%10;     num = num / 10;   }   if (temp == num)     return 1;   else     return 0; } • After getting reverse, we will check whether original and reverse of it are same or not. • If both are same return 1, otherwise return 0.
25th Jan 2019, 8:35 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 7
eerv You are welcome! 😊 Have a nice coding! ;)👍
26th Jan 2019, 2:35 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 5
Hello, 😊 Please, if you want us to help you, then show us your attempt, what you don't understand exactly, where you are struggling, it will be much easier!👍😉 Use the search bar! https://www.sololearn.com/post/10362/?ref=app Please, read our guidelines: https://www.sololearn.com/discuss/1316935/?ref=app An useful code for any new user here! ;) https://code.sololearn.com/WvG0MJq2dQ6y/
25th Jan 2019, 7:56 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 2
eerv Ok, I will help you with textual algorithm!👍
25th Jan 2019, 8:22 PM
Danijel Ivanović
Danijel Ivanović - avatar
+ 1
i can do the prime number part but dont know how to do show the palindromic numbers
25th Jan 2019, 8:18 PM
eerv
eerv - avatar
+ 1
thank you
25th Jan 2019, 8:23 PM
eerv
eerv - avatar
+ 1
Danijel Ivanović thank you for your help. I'll check it as soon as i'm available.
26th Jan 2019, 2:27 PM
eerv
eerv - avatar
0
there is something wrong with this #include <stdio.h> #include <stdlib.h> int prime_num(int x){ int n; scanf("%d",&n); for(x=2;x<=n-1;x++){ if(n%x==0){ return 0; break; } } if(x==n) return 1; } int palindrome_num(int y){ int num, reverse_num=0, temporary_num; scanf("%d",&num); temporary_num=num; while(temporary_num!=0){ reverse_num=reverse_num*10; reverse_num=reverse_num+temporary_num%10; temporary_num=temporary_num/10; } if(num==reverse_num) return 1; else return 0; } int main() { int a, b, i, j=0; scanf("%d %d",&a,&b); for (i=a; i<=b; i++) { if (palindrome_num(i)&&prime_num(i)) j++; } printf("%d",j); return 0; }
28th Jan 2019, 12:57 AM
eerv
eerv - avatar