要求:用C#写!!
试题一   创建一个控制台应用程序, 接受用户分别输入的1个整数,该整数范围是1-10, 
  当X=2时,打印 
  1 
  2  3 
  当X=5时,打印 
  1 
  2  3 
  4  5  6 
  7  8  9  10 
  11 12 13 14 15 
  以此类推

解决方案 »

  1.   

    .....
    //前面控制输入的X为1-10 
    for(int i=0;i<x;i++)
    { int k=1;
    do
    {int m=0;
    for(int p=1;p<=k;p++)
    {for(int t=1;t<=p;t++)
       {m=m+1;
        //这里输出m;   }
     //这里输出一个换行}k++;
    }while(k!=x+1)
    }
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                int x;
                x=Console.Read();
                try
                {
                    x = Convert.ToInt32(((char)x).ToString());
                }
                catch 
                {
                    x = 0;
                }            if (x < 1 || x > 10)
                {
                    Console.Write("invalid argument");
                    Console.Read();
                    Console.Read();
                    Console.Read();
                    return;
                }            int val=1; //要打印的数
                int line = 0; //控制行            for (line = 1; line <= x; line++)
                {
                    //第i 行有i 个数
                    for (int i = 0; i < line; i++)
                    {
                        Console.Write(val);
                        Console.Write("  ");
                        val++;
                    }
                    Console.Write("\n");
                }            Console.Read();
                Console.Read();
                Console.Read();            
            }
        }
    }