给一个int数组,比如说是{1,2,3,4......10}
第一位加第二位  第三位加第四位  ....
输出3,7,11,15,19
如果数组的是奇数 比如{1.......11}
最后输出的是3,7,11,15,19,11

解决方案 »

  1.   

    //沙发
    int[] list = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
    for (int i = 0; i < list.Length; i += 2)
    {
        if (i > 0) Console.Write(",");
        if (i + 1 < list.Length)
            Console.Write(list[i] + list[i + 1]);
        else Console.Write(list[i]);
    }
      

  2.   

    for(int i=0;i<int.Length;)
    {
        if(i+2>=int.Length)
    {
            Console.Write(int[int.Length-1]);
    break;
    }
        else
            Console.Write(int[i]+int[i+1]);
        i+=2;
    }
      

  3.   

    标准化下
                int[] list = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
                for(int i=0;i<list.Length;)
    {
    if(i+2>=list.Length)
    {
    Console.WriteLine(list[list.Length-1]);
    break;
    }
    else
    Console.WriteLine(list[i]+list[i+1]);
    i+=2;
    }
    Console.Read();
      

  4.   

    if(i+2>=list.Length)
    -------------
    if(i+1>=list.Length)
    写错了寒...