Advertisement
B1KMusic

My attempt at fizzbuzz.

Jan 24th, 2016
356
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. /* Source: http://4.bp.blogspot.com/-1ixiCqMw2G8/TxXOx9j-giI/AAAAAAAAD7I/flIVf8Ripdk/s1600/15gebnr.png
  2.  * Description:
  3.  * Write a program that prints the numbers from 1 to 100 [including 100]. But
  4.  * for multiples of three print "Fizz" instead of the number and
  5.  * for the multiples of five print "Buzz" [instead of the number].
  6.  * For numbers which are multiples of both three and five print "FizzBuzz" [instead of the number].
  7.  */
  8.  
  9. #include <stdio.h>
  10.  
  11. #define START 1
  12. #define END   100
  13.  
  14. int divisible(int a, int b){
  15.     return a % b == 0;
  16. }
  17.  
  18. void fbprint(int n){
  19.     int div3 = divisible(n, 3),
  20.         div5 = divisible(n, 5),
  21.         neither = !(div3 || div5);
  22.  
  23.     if(div3)
  24.         printf("Fizz");
  25.  
  26.     if(div5)
  27.         printf("Buzz");
  28.  
  29.     if(neither)
  30.         printf("%i", n);
  31.  
  32.     putchar('\n');
  33. }
  34.  
  35. int main(){
  36.     int i;
  37.  
  38.     for(i = START; i <= END; i++)
  39.         fbprint(i);
  40.  
  41.     return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement