数字瘦身,最后输出一位数,例如: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的主要内容,如果未能解决你的问题,请参考以下文章

逆序数

JS 1000以内的水仙花数 (三位数 各个数字的立方和等于本身 例如 1*1*1 + 5*5*5 + 7*7*7 = 157)

如何在 SQL 中设置滚动的 7 天第 75 个百分位数?

Java/C 求幸运数字 蓝桥杯试题,求解答!求算法!

输出所有的“水仙花数”,所谓“水仙花数”是指一个3位数,其各位数字立方和等于该数本身。例如,153是水仙花数,因为153=1*+5*+3

[PTA]实验7-1-9 数字加密