top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

FizzBuzz using c#

+4 votes
239 views

What is the best way to create FizzBuzz in C#?

posted Sep 19, 2014 by Merry

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+2 votes
 
Best answer
  //Step 1: Print number 1 to 100
  for (int j = 1; j <= 100; j++)
            {
                string result = "";
               //Step 2: Divisible by 3 prints Fizz
                if (j % 3 == 0)
                {
                    result = "Fizz ";
                }
               //Step 3: Divisible by 5 prints Buzz
                if (j % 5 == 0)
                {
                    result = result + "Buzz";
                }
               //Step 4: Divisible by 3 and 5 prints Fizz Buzz

               //Step 5: Print number as it is if not divisible by 3 and 5 

                if (result.Length == 0)
                {
                    result = j.ToString();
                }
                Console.WriteLine(result);
            }
answer Nov 17, 2014 by Manikandan J
Similar Questions
0 votes
public class Semaphore
{
private object _mutex = new object;
private int _currAvail;
public Semaphore(int capacity)
{
_currAvail = capacity;
}
public void Wait()
{
lock(_mutex)
{
if ( currAvail == 0) Monitor.Wait(_mutex);
_currAvail --;
}
}
public void Signal()
{
lock(_mutex)
{
_currAvail ++;
Monitor.Pulse(_mutex);
}
}
}
0 votes

I want to connect a particular MONGODB database to c# application using Web.config.
Please tell me how to do it?

...