程序员 2008第一期 Cantor表 c#实现

来源:互联网 发布:淘宝文案 编辑:程序博客网 时间:2024/04/28 11:15
public static void Cantor(int no)
    {
    int sum=0;
    int i=0;
    int n=0;
    int mother=0;
    int child=0;
        for(i=0;;i++)
        {
            sum+=i;
            n=no-sum;
            if(n>0&&n<=i+1)
            {
                break;
            }
        }
        if(i%2==1)
        {
        child=n;
        mother=i+2-child;
        }
        else
        {
            mother=n;
            child=i+2-mother;
        }

        string result=Convert.ToString(child)+"/"+Convert.ToString(mother);
        Console.WriteLine(result);
}