Interview Question Fizz Buzz example
Solution
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Question :- print number 1 to 100 , the number which are multiple of 3 print fizz , if multiple with 5 print buzz and last if multiple 5 and 3 print fizz buzz.
namespace test
{
class Program
{
static void Main(string[] args)
{
for (int j = 1; j < 100; j++)
{
string results = "";
if (j % 3 == 0)
results = "Fizz";
if (j % 5 == 0)
results = results+"Buzz";
if (j % 7 == 0)
results = results + "Woof";
if (results.Length == 0)
results = j.ToString();
Console.WriteLine(results);
}
Console.ReadLine();
}
}
}
Output
1
2
Fizz
4
Buzz
Fizz
Woof
8
Fizz
Buzz
11
...............Buzz till 100
Solution
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Question :- print number 1 to 100 , the number which are multiple of 3 print fizz , if multiple with 5 print buzz and last if multiple 5 and 3 print fizz buzz.
namespace test
{
class Program
{
static void Main(string[] args)
{
for (int j = 1; j < 100; j++)
{
string results = "";
if (j % 3 == 0)
results = "Fizz";
if (j % 5 == 0)
results = results+"Buzz";
if (j % 7 == 0)
results = results + "Woof";
if (results.Length == 0)
results = j.ToString();
Console.WriteLine(results);
}
Console.ReadLine();
}
}
}
Output
1
2
Fizz
4
Buzz
Fizz
Woof
8
Fizz
Buzz
11
...............Buzz till 100