0

What's wrong with this code?

#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:45 AM
eerv
eerv - avatar
1 Answer
0
So you start with inputs a and b. Why have an a and b to control to control the for loop? What are you trying to do with that? You also have inputs in each of the functions, palindrome and prime, which means that the numbers entered might not be the same. Right now, I see the purpose of this code as counting pairs of user input numbers that are palindrome for the first input and prime for the second. What is your goal for this code? I'm confused about what this should be doing.
28th Jan 2019, 2:12 AM
Zeke Williams
Zeke Williams - avatar