Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
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".
Posted
Updated 7-Feb-14 10:03am
v2

We do not do your homework: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.

Try it yourself, you may find it is not as difficult as you think!
 
Share this answer
 
Comments
Matt U. 7-Feb-14 15:13pm    
This certainly must be homework or something like that. I remember a recruiter asking me this very question recently. I must say, he was surprised at the fact that I responded with the solution in under a minute, and it was 100% correct. Simply because it has a bit of a "trick" to the logic. ;)
Here's the algorithm

Loop through 1 to 100
Begin
1. Divide the number by 3. If the result is 0 then it is said to be a multiple of 3 , Print "Fizz"
2. Divide the number by 5. If the result is 0 then it is said to be a multiple of 5 , Print "Buzz"
3. If Step 1 and Step 2 Results into 0 then print "FizzBuzz"
4. If Step 1 or Step 2 result is not equal to 0 then just print that number.
End
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900