Skip to content

Instantly share code, notes, and snippets.

@fdrobidoux
Created January 12, 2024 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdrobidoux/5b6c9f7e21e68515d9c3d88c7fb90380 to your computer and use it in GitHub Desktop.
Save fdrobidoux/5b6c9f7e21e68515d9c3d88c7fb90380 to your computer and use it in GitHub Desktop.
C# Implementation of a FizzBuzz coding test
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