How to resolve the algorithm 99 bottles of beer step by step in the Odin programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm 99 bottles of beer step by step in the Odin programming language
Table of Contents
Problem Statement
Display the complete lyrics for the song: 99 Bottles of Beer on the Wall.
The lyrics follow this form: ... and so on, until reaching 0 (zero). Grammatical support for 1 bottle of beer is optional. As with any puzzle, try to do it in as creative/concise/comical a way as possible (simple, obvious solutions allowed, too).
Let's start with the solution:
Step by Step solution about How to resolve the algorithm 99 bottles of beer step by step in the Odin programming language
Source code in the odin programming language
package main
import "core:fmt"
printf :: fmt.printf //Give fn on right an arbitrary name, or 9x fmt.printf("...")
bob :: proc( n: int , x: int){
for i := x; i > 0 ; i -=1 {
if n >= 2 do printf("%d bottles of beer",n)
else if n == 1 do printf("1 bottle of beer")
else if n == 0 do printf("No more bottles of beer")
if i == 1 do printf(".\n")
if i > 1 do printf(" on the wall.\n")
if i > 2 do printf("\n")
}
}
main :: proc(){
n := 99
bob(n, 2)
for i := n - 1 ; i >= 0 ; i -= 1 {
printf("Take one down; pass it around.\n")
bob(i, 3)
}
printf ("Go to the store and buy some more.\n")
printf ("%i bottles of beer on the wall.\n",n)
}
You may also check:How to resolve the algorithm Numerical integration step by step in the Ursala programming language
You may also check:How to resolve the algorithm String comparison step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm User input/Text step by step in the C programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the Ruby programming language
You may also check:How to resolve the algorithm Longest common subsequence step by step in the Pascal programming language