Advertisement
A4L

Chapter - 12 - FizzBuzz

A4L
Dec 7th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. /*
  8.     The challenge is to print out all of the numbers from 1 to 100. Except if a number is a multiple of 3,
  9.     print out the word “Fizz” instead. If the number is a multiple of 5, print out “Buzz”. If a number is a
  10.     multiple of both 3 and 5 (like 15 or 30) then print out “FizzBuzz”. For example, “1 2 Fizz 4 Buzz Fizz 7 8
  11.     Fizz Buzz…”
  12. */
  13.  
  14. namespace Chapter___12___FizzBuzz
  15. {
  16.     class Program
  17.     {
  18.         static void Main(string[] args)
  19.         {
  20.             Console.Write("1");
  21.             for (int i=2; i <= 100; i++)
  22.             {
  23.                 if (i % 3 == 0 && i % 5 == 0) { Console.Write(", FizzBuzz"); }
  24.                 else if (i % 3 == 0) { Console.Write(", Fizz"); }
  25.                 else if (i % 5 == 0) { Console.Write(", Buzz"); }
  26.                 else { Console.Write($", {i}"); }
  27.             }
  28.             Console.ReadLine();
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement