Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4265970
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:41:48+00:00 2026-05-21T06:41:48+00:00

I am trying the fizzbuzz program from here: Why Can’t Programmers.. Program? Write a

  • 0

I am trying the fizzbuzz program from here: Why Can’t Programmers.. Program?

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

protected void btn1_Click(object sender, EventArgs e)
    {
        for (int i = 1; i < 101; i++)
        {
            if (i % 3 == 0 & i % 5 == 0)
            {
                Response.Write("fizzbuzz" + ",");
            }
            else if (i % 3 == 0)
            {
                Response.Write("fizz" + ",");
            }
            else if (i % 5 == 0)
            {
                Response.Write("buzz" + ",");
            }
            else
            {
                i = i + 0;
            }

            Response.Write(i +",");
        }

    }

I am able to produce some kind of result like:

1,2,fizz,3,4,buzz,5,fizz,6,7,8,fizz,9,buzz,10,11,fizz,12,13,14,fizzbuzz,15,16,17,fizz,18,19,buzz,20,fizz,21,22,23,fizz,24,buzz,25,26,fizz,27,28,29,fizzbuzz,30,31,32,fizz,33,34,buzz,35,fizz,36,37,38,fizz,39, and so on..

The word fizz was printed but it did not replace 3 and fizzbuzz was printed but it did not replace 15 and so …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T06:41:48+00:00Added an answer on May 21, 2026 at 6:41 am

    Whether you hit the if condition or not you are still printing i at the end of your code.

    Look specifically at your for loop:

    for (int i = 1; i < 101; i++)         
    {             
    if (i % 3 == 0 & i % 5 == 0)             
    {                 
    Response.Write("fizzbuzz" + ",");             
    }             
    else if (i % 3 == 0)             
    {                 
    Response.Write("fizz" + ",");             
    }             
    else if (i % 5 == 0)             
    {                 
    Response.Write("buzz" + ",");             
    }             
    else             
    {                 
    i = i + 0;             
    }              
    Response.Write(i +",");   //look here you print i
    } 
    

    So you need to move that last Response.Write(i + “,”); in the last else condition. The easiest way to find bugs like these is to use the debugger and debug your program. You will then easily see what the output is. So definately use the debugger and set breakpoints / watches and watch what happens. Your code should change to this:

      for (int i = 1; i < 101; i++)         
        {             
        if (i % 3 == 0 & i % 5 == 0)             
        {                 
        Response.Write("fizzbuzz" + ",");             
        }             
        else if (i % 3 == 0)             
        {                 
        Response.Write("fizz" + ",");             
        }             
        else if (i % 5 == 0)             
        {                 
        Response.Write("buzz" + ",");             
        }             
        else             
        {                 
        Response.Write(i +",");   //look here you print i
        }              
        } 
    

    Notice the removal of i=i+1 your for loop is handling this already by incrementing i.

    Edit

    Not sure if this is easier but here is another way to do this using lambda’s:

                List<int> t;
                t = Enumerable.Range(1, 100).ToList();
    
                var fizzBuzz = t.Where(num => num % 3 == 0 && num % 5 == 0);
                var fizz = t.Where(num => num % 3 == 0);
                var buzz = t.Where(num => num % 5 == 0);
                var notFizzBuzz = t.Where(num => num % 3 != 0 && num % 5 !=0);
    
                //print fizzBuzz elements
                Console.WriteLine("Printing fizzBuzz elements...");
                foreach (int i in fizzBuzz)
                    Console.WriteLine(i);
    
                //print fizz elements
                Console.WriteLine("Printing fizz elements...");
                foreach (int i in fizz)
                    Console.WriteLine(i);
    
                //print buzz elements
                Console.WriteLine("Printing buzz elements...");
                foreach (int i in buzz)
                    Console.WriteLine(i);
    
                //print other elements
                Console.WriteLine("Printing all others...");
                foreach (int i in notFizzBuzz)
                    Console.WriteLine(i);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to make a make generic select control that I can dynamically add elements
Trying to honor a feature request from our customers, I'd like that my application,
Trying to create an app that does some socket communication (Writing only). I can
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound
Trying to perform a single boolean NOT operation, it appears that under MS SQL
Trying to track down a bug in an application, but need to confirm whether
Trying to change input type attribute from password to text . $('.form').find('input:password').attr({type:text}); Why this
Trying to replace any non alpha-numeric characters with a hyphen. Can't see why it
Trying to setup an SSH server on Windows Server 2003. What are some good

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.