解题思路应是首先将一个给定大于9的奇数的值翻转(因偶数必为2的倍数就不必测试了,小于10的奇素数反转后仍是自身,也不必测试了),若奇数原值和翻转后的值均为素数,则输出之。所以,应首先实现值翻转和判值是否为素数的这两个函数,然后再主函数中循环即可。示例的C语言代码如下:#include <stdio.h>#include <stdlib.h>//翻转给定值unsigned int ReverseNumber( unsigned int num ){ int i; unsigned int val = 0; for( i=0; num; i++ ) { val *= 10; val += (num % 10); num /= 10; } return val;}//判给定值是否为素数int IsPrime( unsigned int num ){ unsigned int factor; if( num < 2 ) return 0; for( factor=2; factor<=(num/2); factor++ ) { if( num % factor == 0 ) return 0; } return 1;}#define MAX(a,b) ((a)>(b)?(a):(b))#define MIN(a,b) ((a)<(b)?(a):(b))#define MIN_VALUE 1#define MAX_VALUE 100000#define MAX_PER_LINE 5 //每行5个int main( void ){ unsigned int sv, ev, a, b, n, r, cnt = 0; //以下代码保证用户的输入值在题目的规定条件内 do { printf( "Please input start number: " ); scanf( "%d", &sv ); } while( (sv<MIN_VALUE) || (sv>MAX_VALUE) );do { printf( "Please input end number: " ); scanf( "%d", &ev ); } while( (ev<MIN_VALUE) || (ev>MAX_VALUE) );a = MIN( sv, ev ); //较小值赋给a b = MAX( sv, ev ); //较大值赋给b //小于10的值直接忽略 for( n=MAX( a, 10); n<=b; ) { r = ReverseNumber( n ); //若反序后的值与原值不等(注:反序后相等的素数叫对称素数) if( n != r ) { if( IsPrime( n ) && IsPrime( r ) ) //且两值均为素数 { printf( "%d, " ); cnt++; if( cnt % MAX_PER_LINE == 0 ) printf( "\n" ); //另起一行输出 } } if( n & 1 ) n += 2; //若 n 是奇数, 则每次递增步长为2 else n++; //若是偶数则加1变为奇数 } printf( "\nCount: %d\n", cnt );return 0;}