Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
docs:programming:fizzbuzz [2007/07/07 23:20] – billh | docs:programming:fizzbuzz [2008/08/03 00:25] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 2: | Line 2: | ||
* http:// | * http:// | ||
- | ====== Problem | + | ===== FizzBuzz |
//Write a program that prints the numbers from 1 to 100. But for multiples of three print " | //Write a program that prints the numbers from 1 to 100. But for multiples of three print " | ||
Line 34: | Line 34: | ||
./FizzBuzz | ./FizzBuzz | ||
</ | </ | ||
+ | |||
+ | ===== C++ ===== | ||
+ | FIXME | ||
+ | |||
+ | ===== C# ===== | ||
+ | FIXME | ||
===== Java ===== | ===== Java ===== | ||
Line 64: | Line 70: | ||
java FizzBuzz | java FizzBuzz | ||
</ | </ | ||
+ | |||
+ | |||
+ | ===== Perl ===== | ||
+ | **FizzBuzz.pl** | ||
+ | <code perl> | ||
+ | # | ||
+ | |||
+ | my $i; | ||
+ | |||
+ | for($i=1; $i<=100; $i++){ | ||
+ | if($i % 3 == 0 && $i % 5 == 0){ | ||
+ | print " | ||
+ | }elsif($i % 3 == 0){ | ||
+ | print " | ||
+ | }elsif($i % 5 == 0){ | ||
+ | print " | ||
+ | }else{ | ||
+ | print $i . " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | * run< | ||
+ | perl FizzBuzz.pl | ||
+ | </ | ||
+ | |||
+ | ===== Visual Basic ===== | ||
+ | <code vb> | ||
+ | Public Sub FizzBuzz() | ||
+ | Dim i As Integer | ||
+ | |||
+ | For i = 1 To 100 | ||
+ | If (i Mod 3 = 0 And i Mod 5 = 0) Then | ||
+ | Debug.Print " | ||
+ | ElseIf (i Mod 3 = 0) Then | ||
+ | Debug.Print " | ||
+ | ElseIf (i Mod 5 = 0) Then | ||
+ | Debug.Print " | ||
+ | Else | ||
+ | Debug.Print i | ||
+ | End If | ||
+ | Next | ||
+ | End Sub | ||
+ | </ | ||
+ | |||
===== Objective-C (Mac) ===== | ===== Objective-C (Mac) ===== | ||
**FizzBuzz.m** | **FizzBuzz.m** | ||
- | < | + | < |
#import < | #import < | ||
Line 135: | Line 185: | ||
</ | </ | ||
- | ===== Correct Output ===== | + | |
+ | ===== Javascript/ | ||
+ | **FizzBuzz.htm** | ||
+ | <code javascript> | ||
+ | <script type=" | ||
+ | var i; | ||
+ | |||
+ | for(i=1; i<=100; i++){ | ||
+ | if(i % 3 == 0 && i % 5 == 0){ | ||
+ | document.write(" | ||
+ | }else if(i % 3 == 0){ | ||
+ | document.write(" | ||
+ | }else if(i % 5 == 0){ | ||
+ | document.write(" | ||
+ | }else{ | ||
+ | document.write(i + "< | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ===== Shell Script ===== | ||
+ | FIXME | ||
+ | |||
+ | ===== Correct Output | ||
< | < | ||
1 | 1 |