Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A
dotnetinter

QuestPond’s Interview Questions & Answers on .NET

How to write a FizzBuzz program in C#?

Ok first let me explain what is FizzBuzz, Fizz

"Write a c# program that prints numbers from 1 to 100. But for multiples of 3 print “Fizz” instead of the number and for the multiples of 5 print “Buzz”. For numbers which are multiples of both 3 and 5  print “FizzBuzz”.

for (int j = 1; j <= 100; j++)
 {
      string Output = "";

      if (j % 3 == 0) Output = "Fizz";// Divisible by 3 --> Fizz

      if (j % 5 == 0) Output += "Buzz"; // Divisible by 5 --> Buzz

      if (Output == "") Output = j.ToString(); // If none then --> number

      Console.WriteLine(Output); // Finally print the complete output
 }


Click and see here for more programming algorithm in .NET
Tags: .net interview questions, .net step by step training, .net training, algorithm, csharp interview questions, fizzbuzz, it interview questions with answers, programming algorithm, programming interview questions
Subscribe

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments