Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language MATLAB

(Recursive)

Date:11/24/08
Author:William Rossi
URL:n/a
Comments:0
Info:http://mathworks.com
Score: (3.00 in 6 votes)
function b = bottles(A)
% Call this function by typing 'bottles(99)'
if A==2
    fprintf('2 bottles of beer on the wall, 2 bottles of beer.\n')
    fprintf('Take one down and pass it around, one bottle of beer on the wall.\n\n')
    fprintf('1 bottle of beer on the wall, 1 bottle of beer.\n')
    fprintf('Take one down and pass it around, no more bottles of beer on the wall.\n\n')
    fprintf('No more bottles of beer on the wall, no more bottles of beer.\n')
    fprintf('Go to the store and buy some more, 99 bottles of beer on the wall.\n\n')
else
    fprintf('%.0f bottles of beer on the wall, %.0f bottles of beer.\n',A,A)
    fprintf('Take one down and pass it around, %.0f bottles of beer on the wall.\n\n',(A-1))
    bottles(A-1);
end

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
vectorized versionRich Stein04/20/050
standard versionBill Becker04/20/051

Comments

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: