017_quiz2.zig 857 B

1234567891011121314151617181920212223242526272829
  1. //
  2. // Quiz time again! Let's see if you can solve the famous "Fizz Buzz"!
  3. //
  4. // "Players take turns to count incrementally, replacing
  5. // any number divisible by three with the word "fizz",
  6. // and any number divisible by five with the word "buzz".
  7. // - From https://en.wikipedia.org/wiki/Fizz_buzz
  8. //
  9. // Let's go from 1 to 16. This has been started for you, but there
  10. // are some problems. :-(
  11. //
  12. const std = @import("std");
  13. pub fn main() void{
  14. var i: u8 = 1;
  15. const stop_at: u8 = 16;
  16. // What kind of loop is this? A 'for' or a 'while'?
  17. while(i <= stop_at) : (i += 1){
  18. if(i % 3 == 0){ std.debug.print("Fizz", .{}); }
  19. if(i % 5 == 0){ std.debug.print("Buzz", .{}); }
  20. if(!(i % 3 == 0) and !(i % 5 == 0)){
  21. std.debug.print("{}", .{i});
  22. }
  23. std.debug.print(", ", .{});
  24. }
  25. std.debug.print("\n", .{});
  26. }