FOR A 1 TO 100 IF A MOD 15 0 THEN PRINT FizzBuzz ELSE IF A MOD 3 0 THEN PRINT Fizz ID: 284643
Download Presentation The PPT/PDF document "Basic" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Basic
FOR A=1 TO 100 IF A MOD 15 = 0 THEN PRINT “FizzBuzz” ELSE IF A MOD 3 = 0 THEN PRINT “Fizz” ELSE IF A MOD 5 = 0 THEN PRINT “Buzz” ELSE PRINT A END IF NEXT A
1964
Simple,
Many Implementations
Computer Science, Education, Scripting, Games
Imperative, Object Oriented (some variations)Slide2
C
#include <stdio.h> int main (int argc, char** argv) { int i; for (i = 1; i <= 100; i++) { if (!(i % 15)) printf("FizzBuzz\n"); else if (!(i % 3)) printf("Fizz\n"); else if (!(i %
5))
printf
("Buzz\n");
else printf
("%d\n",
i); }
return
0
; }
1972
High Performance, Low Level, Pervasive
Operating Systems, Compilers, Interpreters, Embedded Processors, Games
Imperative,
Static Typing
http://www.cprogramming.com/tutorial.htmlSlide3
Scheme
(define (fizzify i) (cond ((= (modulo i 15) 0) "FizzBuzz") ((= (modulo i 3) 0) "Fizz") ((= (modulo i 5) 0) "Buzz") (#t i) ) ) (define (fizzbuzz i) (if (<= i 100) (begin (display (fizzify i)) (display "\n") (fizzbuzz (+
i
1))
) )
) (
fizzbuzz 1)
1975
Homoiconic
,
Minimalistic,
Cross Platform
Computer ScienceEducation, Scripting,
Academic Research
Functional,Tail Call Recursion,Dynamic Typing
http://www.schemers.orgSlide4
Python
for i in range(1, 101): if i % 15 == 0: print "FizzBuzz" elif i % 3 == 0: print "Fizz" elif i % 5 == 0: print "Buzz" else: print( i )1991Cross Platform,Duck Typing,Indentation Syntax,InterpreterComputer ScienceEducation, Scripting,Internet, GamesImperative,Object Oriented,Dynamic Typing
http://www.python.orgSlide5
Java
public class FizzBuzz { public static void main (String[] args) { for (int i = 1; i <= 100; i++) { if (i % 15 == 0) { System.out.println("FizzBuzz"); } else if (i % 3 == 0) { System.out.println("Fizz"); } else if (i % 5 == 0) { System.out.println("Buzz");
} else {
System.out.println(
i); }
} }
}
1995
Interoperability,
Standardised,
Cross PlatformApplications,
Mobile Devices, Compilers,Interpreters, Games
Imperative,
Object Oriented,Static Typing,Generics
http://www.java.comSlide6
Ruby
1.upto(100) do |n| print "Fizz" if a = (n % 3).zero? print "Buzz" if b = (n % 5).zero? print n unless (a || b) print "\n" end1995Cross Platform,Duck TypingInternet, ScriptingImperative,Object Oriented,Dynamic Typing,Functionalhttp://www.ruby-lang.orgSlide7
C#
using System; namespace FizzBuzz { class Program { static void Main(string[] args) { for (int i = 1; i <= 100; i++) { string output = ""; if (i % 3 == 0) output += "Fizz"; if (i % 5 == 0) output += "Buzz"; if (
String.IsNullOrEmpty(output))
output =
i.ToString();
Console.WriteLine
(output); }
} }
}
2001
Standardised,
Common Language
Runtime
Applications, Internet,
Business, Games
Imperative,Object Oriented,Static TypingSlide8
Scratch
2007Rich Media,Online Collaboration,Animation,Cross PlatformComputer ScienceEducationFixed Function,Imperative,Visual Programminghttp://scratch.mit.edu/Slide9
PHP
<?php for(a = 1; a <= 100; a++) { if(a % 15 == 0) echo “FizzBuzz”; elsif(a % 3 == 0) echo “Fizz”; elsif(a % 5 == 0) echo “Buzz”; } ?>1995
Cross Platform,
Interpreter
Computer Science, Education, Internet, Scripting
Imperative, Object Oriented, Dynamic Typing
http://www.php.netSlide10
Java Script
for (a=1; a<=100; a++) if(a%15 ===0){ console.log("FizzBuzz"); } else if ( a % 3 === 0 ) { console.log("Fizz"); } else if (a % 5 === 0 ) { console.log("Buzz"); } else { console.log(a); } }1995Weakly Typed,Cross PlatformWeb Pages,PDF,WidgetsScripting, Object Oriented, Imperative,FunctionalSlide11
Visual Basic.net
For a = 1 To 100If a Mod 15 = 0 Then Console.WriteLine("FizzBuzz")ElseIf a Mod 5 = 0 Then Console.WriteLine("Buzz")ElseIf a Mod 3 = 0 Then Console.WriteLine("Fizz")Else Console.WriteLine(a)End IfNext2001Intuative forms designer.Simple syntax.Flexible.General purpose.Office applications and tools.Gaming.Structured,Imperative,Object Oriented,DeclarativeSlide12
Pascal
program fizzbuzz(output);vara: integer;beginfor a := 1 to 100 do if a mod 15 = 0 then writeln('FizzBuzz') else if a mod 3 = 0 then writeln('Fizz') else if a mod 5 = 0 then writeln('Buzz') else writeln(a)end.1968Easy to learn.
Encourages good style.
Education
Imperative,StructuredSlide13
COBOL
IDENTIFICATION DIVISION. PROGRAM-ID. fizzbuzz. DATA DIVISION. WORKING-STORAGE SECTION 01 CNT PIC 9(03) VALUE 1. 01 REM PIC 9(03) VALUE 0. 01 QUOTIENT PIC 9(03) VALUE 0. PROCEDURE DIVISION. *PERFORM UNTIL CNT > 100 DIVIDE 15 INTO CNT GIVING QUOTIENT REMAINDER REM IF REM = 0 THEN DISPLAY "FizzBuzz " WITH NO ADVANCING ELSE DIVIDE 3 INTO CNT GIVING QUOTIENT REMAINDER REM IF REM = 0 THEN DISPLAY "Fizz " WITH NO ADVANCING
ELSE
DIVIDE 5 INTO
CNT GIVING QUOTIENT
REMAINDER REM
IF REM = 0
THEN DISPLAY "
Buzz
" WITH NO ADVANCING
ELSE
DISPLAY CNT " " WITH NO ADVANCING
END-IF END-IF
END-IF ADD
1 TO
CNT END-PERFORM
DISPLAY "“ STOP RUN.
1959
Verbose so more like a natural language
Business Processes
Batch Programming
Procedural,
Object OrientedSlide14
Perl
foreach (1 .. 100) {if (0 == $_ % 15) { print "FizzBuzz\n";} elsif (0 == $_ % 3) { print "Fizz\n";} elsif (0 == $_ % 5) { print "Buzz\n";} else { print "$_\n";};};1987Reusable ModulesDynamic ConversionText ProcessingScriptingGraphicsNetworkingFunctional, Imperative, Object Oriented, ProceduralSlide15
BBC Basic
FOR a% = 1 TO 100CASE TRUE OF WHEN a% MOD 15 = 0: PRINT "FizzBuzz" WHEN a% MOD 3 = 0: PRINT "Fizz" WHEN a% MOD 5 = 0: PRINT "Buzz" OTHERWISE: PRINT ; a%ENDCASENEXT a%1981Weakly typedWidely supportedEducationGamingProceduralSlide16
Algol
main:( FOR a TO 100 DO printf(($gl$, IF a %* 15 = 0 THEN "FizzBuzz" ELIF a %* 3 = 0 THEN "Fizz" ELIF a %* 5 = 0 THEN "Buzz" ELSE a FI )) OD)1958No easy input/outputResearchPublishing AlgorithmsProcedural,Imperative,Structured