//#include "stdafx.h"//vc++6.0加上這一行.#include "stdio.h"#include "string.h"#include "stdlib.h"bool prime(int n){ int i; if(n<2) return false; if(n==2 || n==3) return true; if(!(n%2)) return false; for(i=3; i*i<=n;i+=2) if(!(n%i)) return false; return true;}bool palindrome(int n){ char a[5]="",b[5]=""; itoa(n,a,10); if(!strcmp(a,strrev(strcpy(b,a)))) return true; return false;}void main(void){ int i,ln; printf("%5d",2); for(ln=1,i=3;i<10000;i+=2) if(prime(i) && palindrome(i)) printf(++ln%5 ? "%5d" : "%5d\n",i); printf("\n");}
//#include "stdafx.h"//vc++6.0加上這一行.#include "stdio.h"#include "string.h"#include "stdlib.h"bool prime(int n){ int i; if(n<2) return false; if(n==2 || n==3) return true; if(!(n%2)) return false; for(i=3; i*i<=n;i+=2) if(!(n%i)) return false; return true;}bool palindrome(int n){ char a[5]="",b[5]=""; itoa(n,a,10); if(!strcmp(a,strrev(strcpy(b,a)))) return true; return false;}void main(void){ int i,ln; printf("%5d",2); for(ln=1,i=3;i<10000;i+=2) if(prime(i) && palindrome(i)) printf(++ln%5 ? "%5d" : "%5d\n",i); printf("\n");}