码迷,mamicode.com
首页 > 编程语言 > 详细

小算法:将一整数逆序后放入一数组中(要求递归实现)

时间:2014-10-23 11:57:18      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   ar   for   sp   div   on   

static void Main(string[] args)
        {
            int m = 1236578;
            int[] ms = new int[m.ToString().Length];
            Rev(m.ToString().Length, m, ref ms);
            for (int i = 0; i < m.ToString().Length; i++)
                Console.Write("{0}", ms[i]);
            Console.ReadLine();
        }

 private static void Rev(int len, int m, ref int[] ms)
        {
            if (m / 10 > 0)
            {
                ms[len - m.ToString().Length] = m % 10;
                Rev(len, m / 10, ref ms);
                return;
            }
            ms[len - m.ToString().Length] = m % 10;
        }

 

小算法:将一整数逆序后放入一数组中(要求递归实现)

标签:style   blog   color   os   ar   for   sp   div   on   

原文地址:http://www.cnblogs.com/PeterJin/p/4045223.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!