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
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
vectorized version | Rich Stein | 04/20/05 | 0 | |
standard version | Bill Becker | 04/20/05 | 1 |
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!
Comments