文档创建日期:2010-02-20
问题来源:http://topic.csdn.net/u/20100219/22/63c9d042-2520-4cc0-8139-3c0c89f86ae5.html
只回复第一问:
01 // Test.c
02
03 // Header files included.
04 #include <stdio.h>
05
06 // No.1: Subroutine: int palindrome ( long int i_num ); 判断是否回文
07 int palindrome ( long int i_num )
08 {
09 int i=0;
10 long int temp=0, target=0;
11 temp = i_num;
12 if ( temp == 0 )
13 return (1);
14 while ( temp != 0 )
15 {
16 target = target*10 + temp%10;
17 temp = temp / 10;
18 }
19 if ( target != i_num )
20 return (0);
21
22 // 返回1为回文,返回0表示不是回文
23 return (1);
24 }
25
26 // Main function's declaration.
27 int main ( void )
28 {
29 int i=0, mark=0, count=0;
30 long int temp=0;
31 printf ( "The palindrome number is (11~9999):/n" );
32 for ( i=11; i <=9999; i++ )
33 {
34 temp = (long int) i;
35 mark = ( palindrome(temp) & palindrome(temp*temp)
36 & palindrome(temp*temp*temp) );
37 if ( mark==0 )
38 continue;
39 else
40 if ( mark==1 )
41 {
42 printf ( "%7d", i );
43 count++;
44 if ( count%8 == 0 )
45 printf ( "/n" );
46 }
47 }
48 printf ( "/n" );
49 printf ( "There are %d palindrome numbers between 11 and 9999./n", count );
50
51 return (0);
52 }
53
54 // The end.