Last active
August 22, 2025 09:47
-
-
Save okekevicktur/7e0693d1cbd3a2d264bc7222e348c10d to your computer and use it in GitHub Desktop.
Write a Cairo program that prints numbers from 1 to 100, with the following conditions: For multiples of 3: print "Fizz”. For multiples of 5: print "Buzz. For multiples of both 3 and 5: print "FizzBuzz”. For all other numbers: print the number itself. Mode of Submission: Github Gist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn main() { | |
| println!("FizzBuzz Program Output:"); | |
| println!("-------------------------"); | |
| println!("Fizz = multiple of 3"); | |
| println!("Buzz = multiple of 5"); | |
| println!("FizzBuzz = multiple of both 3 and 5"); | |
| println!("Numbers = all other cases\n"); | |
| let mut i:usize = 1; | |
| loop { | |
| if i > 100 { | |
| break; | |
| } | |
| //This allows mutiple of 3 and 5 as 5 * 3 = 15. dividing it and the result giving no reminder hence the use of modulus | |
| if i % 15 == 0 { | |
| println!("FizzBuzz"); | |
| } else if i % 3 == 0 { | |
| println!("Fizz"); | |
| } else if i % 5 == 0 { | |
| println!("Buzz"); | |
| } else { | |
| println!("{}", i); | |
| } | |
| i += 1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good job, keep it up. Although you failed to comments your logic flow as instructed...