Writing FizzBuzz

后端 未结 30 2092
庸人自扰
庸人自扰 2020-12-04 08:50

Reading the coding horror, I just came across the FizzBuzz another time.

The original post is here: Coding Horror: Why Can\'t Programmers.. Program?

For thos

30条回答
  •  情歌与酒
    2020-12-04 09:07

    A functional approach...

    Console.WriteLine(Enumerable
        .Range(1,100)
        .Aggregate("", 
            (a,i) => a + "\n" + (i%15==0 ? "fizzbuzz" : 
                                    (i%5==0 ? "buzz" :
                                        (i%3==0 ? "fizz" : i.ToString())))));
    

提交回复
热议问题