Print reverse pyramid of numbers

前端 未结 5 803
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-29 17:08

I am able to print pyramid like this :

   1
  123
 12345
1234567

Code i used to print the pyramid of numbers like a

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-29 17:21

            int numberofdigits = 7;
            int numberofdigitsforrow = 0;
            int Emptyspace = 0;
    
            for (int i = 0; i < numberofdigits; i++)
            {
                numberofdigitsforrow = numberofdigits - i * 2;
                if (numberofdigitsforrow > 0)
                {
                    Emptyspace = numberofdigits-numberofdigitsforrow;
                    if (Emptyspace > 0)
                    {
                        for (int b = 1; b <= Emptyspace/2; b++)
                        {
                            Console.Write(" ");
    
                        }
                    }
                    for (int c = 1; c <= numberofdigitsforrow; c++)
                    {
                        Console.Write(c.ToString());
                    }
                    if (Emptyspace > 0)
                    {
                        for (int b = 1; b <= Emptyspace / 2; b++)
                        {
                            Console.Write(" ");
                        }
                    }
                    Console.WriteLine();
                }
            }
    

提交回复
热议问题