去某知名公司面试题


1
12
123
1234
12345

自己回来写的代码:

 static void Main(string[] args)
        {
     

            for (int i = 1; i < 5; i++)
            {
                string result="";
                for (int j = 1; j <=i; j++)
                {
                    //result = result + j.ToString();
                    Console.Write(j.ToString());

                }
                Console.WriteLine();
               

            }
        }

第一个loop制作N个行数和给最大数,第二个loop则从第一个loop接收最大数,并从1开始写数。

第二道题目:打印以下字符,写一个方法

1

21

123

4321

12345

     public static void op2(int n)
        {
            for (int i = 1; i < n; i++)
            {

                if (i % 2 == 1)
                {
                    for (int j = 1; j <= i; j++)
                    {
                        Console.Write(j.ToString());

                    }
                }
                else
                {
                    for (int j = i; j >= 1; j--)
                    {
                        Console.Write(j.ToString());

                    }
                }
                Console.WriteLine();


            }
        }
作者:johnny 出处:http://www.cnblogs.com/sunjunlin 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/sunjunlin/p/2607268.html