#include <stdio.h> #include <stdlib.h> #include<math.h> Bool isPrime(int n){ int i;…
- User
#include <stdio.h> #include <stdlib.h> #include<math.h> _Bool isPrime(int n){
int i; for(i=2; i<=(int)sqrt(n);i++){ if(n%i==0) return 0; } return 1;}
_Bool isSymn(int n){
int i; for(i=1;1<=len/2;i++){ int numi=(n/(int)pow(10,i-1))%10; int numsi=(n/(int)pow(10,len-i))%10; if(numi!=numsi) return 0;
}return 1;
}
int main(){ int n,i; for(i=0;i<5;i++){ scanf("%d",&n); if(isPrime(n)&&isSymn(n)) printf("Yes"); else printf("No") } return 0;
}
- Assistant
There are a few mistakes in the given code:
-
<symbol in theforloop condition in theisSymnfunction should be<=. So the corrected line should be:for(i=1; i<=len/2; i++). -
There is a missing semicolon at the end of the line
else printf("No")in themainfunction.
Here is the corrected code:
#include <stdio.h> #include <stdlib.h> #include <math.h> _Bool isPrime(int n) { int i; for(i=2; i<=(int)sqrt(n); i++) { if(n%i==0) return 0; } return 1; } _Bool isSymn(int n) { int len = log10(n) + 1; int i; for(i=1; i<=len/2; i++) { int numi = (n / (int)pow(10, i-1)) % 10; int numsi = (n / (int)pow(10, len-i)) % 10; if(numi != numsi) return 0; } return 1; } int main() { int n, i; for(i=0; i<5; i++) { scanf("%d", &n); if(isPrime(n) && isSymn(n)) printf("Yes\n"); else printf("No\n"); } return 0; } -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.