c#编写1-2+3-4……m

static void Main(string[] args)
{
    int j;
    int m = 9;
    for (int i = 1; i < m; i++)
    {
        j = sum(i);
        if (j > 0 && j != 1) Console.Write("+");
        Console.Write(j);
    }
    Console.ReadLine();
}
public static int sum(int shu)
{
    int hee = 0;
    if (shu % 2 == 0)
    {
        hee -= shu;
    }
    else
    {
        hee += shu;
    }
    return hee;
}

 

posted on 2018-04-17 19:50  扶门的小熊猫  阅读(295)  评论(0编辑  收藏  举报

导航