数字瘦身,最后输出一位数,例如:75 7+5=12 1+2=3 最终答案 3

Posted xiaolang0

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数字瘦身,最后输出一位数,例如:75 7+5=12 1+2=3 最终答案 3相关的知识,希望对你有一定的参考价值。

数字瘦身,最后输出一位数,例如:75    7+5=12   1+2=3 最终答案  3

using System;

public class Solution

{

    private int renum;

    public int diet(int in_num)

    {

        renum = 0;

        while (in_num / 10 > 0)

        {

            renum = renum + in_num % 10;

            in_num = in_num / 10;

        }

        renum = renum + in_num;

        if (renum > 10)

        {

            diet(renum);

        }

        return renum;

    }

}

public class Program

{

    public static void Main(string[] args)

    {

        string s = Console.ReadLine();

        int in_num = int.Parse(s);

        Solution solution = new Solution();

        int out_num = solution.diet(in_num);

        Console.WriteLine(out_num);

        Console.ReadKey();

    }

}

注:主要使用递归方法diet实现基本功能……

以上是关于数字瘦身,最后输出一位数,例如:75 7+5=12 1+2=3 最终答案 3的主要内容,如果未能解决你的问题,请参考以下文章