How to resolve the algorithm FizzBuzz step by step in the V (Vlang) programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm FizzBuzz step by step in the V (Vlang) programming language
Table of Contents
Problem Statement
Write a program that prints the integers from 1 to 100 (inclusive).
But:
The FizzBuzz problem was presented as the lowest level of comprehension required to illustrate adequacy.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm FizzBuzz step by step in the V (Vlang) programming language
Source code in the v programming language
const (
fizz = Tuple{true, false}
buzz = Tuple{false, true}
fizzbuzz = Tuple{true, true}
)
struct Tuple{
val1 bool
val2 bool
}
fn fizz_or_buzz( val int ) Tuple {
return Tuple{ val % 3 == 0, val % 5 == 0 }
}
fn fizzbuzz( n int ) {
for i in 1..(n + 1) {
match fizz_or_buzz(i) {
fizz { println('Fizz') }
buzz { println('Buzz') }
fizzbuzz { println('FizzBuzz') }
else { println(i) }
}
}
}
fn main(){
fizzbuzz(15)
}
fn main() {
mut i := 1
for i <= 100 {
match true {
i % 15 == 0 { println('FizzBuzz') }
i % 3 == 0 { println('Fizz') }
i % 5 == 0 { println('Buzz') }
else { println(i) }
}
i++
}
}
fn main() {
for i in 1..100 {
if i % 15 == 0 {
println('FizzBuzz')
} else if i % 3 == 0 {
println('Fizz')
} else if i % 5 == 0 {
println('Buzz')
} else {
println(i)
}
}
}
You may also check:How to resolve the algorithm Create an object at a given address step by step in the Commodore BASIC programming language
You may also check:How to resolve the algorithm Percentage difference between images step by step in the Frink programming language
You may also check:How to resolve the algorithm Operator precedence step by step in the COBOL programming language
You may also check:How to resolve the algorithm Angles (geometric), normalization and conversion step by step in the Groovy programming language
You may also check:How to resolve the algorithm Topological sort step by step in the Nim programming language