Created
January 12, 2024 19:27
-
-
Save fdrobidoux/5b6c9f7e21e68515d9c3d88c7fb90380 to your computer and use it in GitHub Desktop.
C# Implementation of a FizzBuzz coding test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.CodeDom.Compiler; | |
using System.Collections.Generic; | |
using System.Collections; | |
using System.ComponentModel; | |
using System.Diagnostics.CodeAnalysis; | |
using System.Globalization; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
using System.Runtime.Serialization; | |
using System.Text.RegularExpressions; | |
using System.Text; | |
using System; | |
class Result | |
{ | |
/* | |
* Complete the 'fizzBuzz' function below. | |
* | |
* The function accepts INTEGER n as parameter. | |
*/ | |
public static void fizzBuzz(int n) | |
{ | |
for (int i = 1; i <= n; i++) { | |
bool once = false; | |
if (i % 3 == 0) { | |
Console.Write("Fizz"); | |
once = true; | |
} | |
if (i % 5 == 0) { | |
Console.Write("Buzz"); | |
once = true; | |
} | |
if (!once) { | |
Console.Write(i); | |
} | |
Console.Write("\n"); | |
} | |
} | |
} | |
class Solution | |
{ | |
public static void Main(string[] args) | |
{ | |
int n = Convert.ToInt32(Console.ReadLine().Trim()); | |
Result.fizzBuzz(n); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment