帮助CSDN网友完成的一个程序

文档创建日期: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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值