Recently I started looking for a new role, a new developer role. During my interviews, I have come across a number of questions and coding challenges. For each of these challenges, I take my time, create the code. I then come home and revisit that challenge to write a better solution.

Recently I started looking for a new role, a new developer role. During my interviews, I have come across a number of questions and coding challenges. For each of these challenges, I take my time, create the code. I then come home and revisit that challenge to write a better solution.

In this new solution I create it in a few different languages, just to challenge myself, but to also provide my solution to anyone who maybe looking for the solution the this quiz question.

For this challenge I take one of the common coding quizzes I've seen asked during an interview is the FizzBuzz code question.

FizzBuzz

What is FizzBuzz? Simply put, its a challenge that will print one of 3 words when a number is divisible by a given number, and if not divisible it will output the number.

So, it seems common to give the following parameters:

  1. Number range is 1 to 100
  2. If the number is divisible by 3 then output Fizz
  3. If the number is divisible by 5 then output Buzz
  4. If the number is divisible by 3 and 5 then output Fizzbuzz
  5. If the number is not divisible by the above values, output the value

FizzBuzz in C#

Given the above parameters, here is my solution for this FizzBuzz challenge written in C#

using System;

namespace FizzBuzz
{
    class Program
    {
        static void Main(string[] args)
        {
            bool found = false;

            for(int counter=1; counter <= 100; counter++)
            {
                if(counter%3 == 0)
                {
                    Console.Write("Fizz");
                    found = true;
                }

                if(counter%5 == 0)
                {
                    Console.Write("Buzz");
                    found = true;
                }

                if (!found)
                {
                    Console.Write(counter);
                }

                Console.WriteLine();
                found = false;
            }
        }
    }
}
Sean

Share
Published by
Sean

Recent Posts

The Question: Cream or Jam First

So, to set the scene. I'm currently away on a break. I was out walking…

1 year ago

Creating a WordPress SEO Plugin From Scratch

Creating a WordPress SEO plugin from scratch is an ambitious yet rewarding endeavor that can…

1 year ago

A Step-by-Step Guide to Building an API Endpoint with Java Spring Boot

Introduction to API Endpoint Development Understanding API Endpoints API endpoints serve as the communicative bridges…

2 years ago

The Fine Line Between Knowledge and Overwhelm: Signs You're Learning Too Much

The innate human desire to learn and grow is a fundamental part of our nature.…

2 years ago

Demystifying the @Transactional Annotation in Spring Boot

When working within the Spring framework, developers often encounter scenarios where transactional integrity is crucial…

2 years ago

Demystifying @Autowired in Java Spring Boot: A Beginner's Guide

Introduction to @Autowired in Java Spring Boot What is Dependency Injection? Dependency Injection (DI) is…

2 years ago