0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【C#】fizzbuzz問題を解いてみた

Posted at

#fizzbuzz問題とは?
入力した値まで、1から順に3の倍数のときはfizz、5の倍数のときはbuzz、3と5の倍数のときはfizzbuzzと表示するもの。

#環境
Visual Stadio2019

#ソースコード

using System;

namespace fizzbuzz
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            Console.WriteLine("数字を入力してください");
            int max = int.Parse(Console.ReadLine());
            while (count < max)
            {
                count++;
                if (count % 3 == 0 && count % 5 == 0)
                {
                    Console.WriteLine("fizzbuzz");
                }
                else if (count % 3 == 0)
                {
                    Console.WriteLine("fizz");
                }
                else if (count % 5 == 0)
                {
                    Console.WriteLine("buzz");
                }
                else
                {
                    Console.WriteLine(count);
                }
            }
        }
    }
}

#ポイント
ポイントというほどでもないですが、最初のif文「3の倍数かつ5の倍数」ではなく、「15の倍数」でもよかったですね

#最後に
Qiitaの記事を書く練習もかねて投稿しました。
次はオブジェクト指向で勉強したことについても書いてみようと思います。

0
1
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?