Writing FizzBuzz

后端 未结 30 2046
庸人自扰
庸人自扰 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:08

    I'll add mine even though there's 20 other solutions already written: It goes like this....

    var x = 1;
    while (x <= 100)
    {
         if (x % 3 == 0 && x % 5 == 0)
            {Console.Writeline("FizzBuzz");}
         else if (x % 3 == 0)
            {Console.Writeline("fizz");}
         else if (x % 5 == 0)
            {Console.Writeline("Buzz");}
         else
            {Console.Writeline(x);}
         x++ 
    }
    

    First solution I came up with. Simple, to the point and gets the job done. No need for bool.

提交回复
热议问题