接受2个数字num1和num2.找出这2个数字之间所有奇数的和!- -| 回首页 | 2005年索引 | - -汉诺塔算法的源程序!

从低位开始取出长整数变量S的奇位数!- -

                                      

 从低位开始取出长整型变量s中奇数位上的数,依次构成一个新数放在t中。例如,当s中的数为:7654321时,t中的数为:7531。

#include <conio.h>
  #include <stdio.h>

  main()
  { long   s, t, sl=10;
    clrscr();
    printf("\nPlease enter s:");
    scanf("%ld", &s);
    t = s %10;
    while ( s > 0)
    {   s = s/100;
        t = s%10 * sl + t;
        sl = sl*10;
    }
    printf("The result is: %ld\n", t);
  }

- 作者: 刘加开 2005年03月16日, 星期三 16:20 加入博采

Trackback

你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=951048

回复

评论内容: