#include stdio.h
int main(void)
{
printf("#include stdio.h\nint main(void)\n{\n");
int i;
for (i = 1; i = 100; i++)
{
printf("\tprintf("");
if (i % 3 == 0 i % 5 == 0)
printf(“FizzBuzz”);
else if (i % 3 == 0)
printf(“Fizz”);
else if (i % 5 == 0)
printf(“Buzz”);
else
printf("%d", i);
printf("");\n");
}
printf("\treturn 0;\n}\n");
return 0;
}
Writing a program that satisfies your FizzBuzz specification is trivial in any language. The solve the specification you can simply write out the precomputed solution:
println(“1 2 Fizz 4 Buzz Fizz 7 8 Fizz Buzz …”);
This gives you also the best runtime performance …
//define your own output method with TRACE
void fizzbuzz(int i = 1)
{
if (i 100) return;
(i%15)?(i%3)?(i%5)?TRACE("%d",i):TRACE(“Buzz”):TRACE(“Fizz”):TRACE(“FizzBuzz”);
TRACE("\n");
fizzbuzz(++i);
}
void main()
{
fizzbuzz();
}
//yep, I know this kinf of code is a nightmare for thos who will mantain this code later
For i = 1 To 100
Response.Write("br/")
If (i Mod 3 = 0) Then
Response.Write("Fizz")
End If
If (i Mod 5 = 0) Then
Response.Write("Buzz")
ElseIf (i Mod 3 0 And i Mod 5 0) Then
Response.Write(i)
End If
Next
End Sub
For the VBScripters that were arguing over carriage returns, a CSscript solution in about 30 seconds:
Dim i
For i = 1 to 100
If i mod 3 = 0 Then WScript.StdOut.Write "Fizz"
If i mod 5 = 0 Then WScript.StdOut.Write "Buzz"
If CBool(i mod 3) And CBool(i Mod 5) Then WScript.StdOut.Write i
WScript.Echo ""
Next
Next we use VBScript to do it in ASP (ok, this is cheating ):
%
Option Explicit
Dim i
For i = 1 to 100
If i mod 3 = 0 Then Response.Write "Fizz"
If i mod 5 = 0 Then Response.Write "Buzz"
If CBool(i mod 3) And CBool(i Mod 5) Then Response.Write i
Response.Write "br/"
Next
%
Then something else…python?
a = []
for i in range(1,101):
a.append((i%15==0) and “FizzBuzz” or ((i%5==0) and “Buzz” or ((i%3==0) and “Fizz” or str(i))))
print a
Damn, time to take a shower and go to work. I think I just wasted most of my morning reading the other replies before I spent a couple minutes writing those three
for (int i = 1; i = 100; i++) {
if (i % 3 == 0 || i % 5 == 0) {
if (i % 3 == 0) {
Console.Write(“Fizz”);
}
if (i % 5 == 0) {
Console.Write(“Buzz”);
}
}
else {
Console.Write(i.ToString());
}
Console.Write("\n");
}
i’m sick of seeing C/C++ and other {} enclosed solutions so here’s my VB6 version. spent less than 5 minutes on it, which is terrible going by other’s standards.
dim num as byte, printstr as string
for num=1 to 100
printstr=""
if num mod 3 = 0 then printstr=printstr “Fizz"
if num mod 5 = 0 then printstr=printstr “Buzz"
if printstr”” then
debug.print printstr
else
debug.print num
end if
next
btw, i’m not proving myself. i’m 18, and i’ve already tried making a 2d game in VB6. oddly enough, it failed.
all this degrading of other applicants has made me want to apply for a programming job now! still at school for 3 months though.
God, i’m so arrogant.