123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- /* Copyright © 2015, 2018 Jeffrey Cliff
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or (at
- * your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- */
- #include "stdio.h"
- void fizzbizz();
- // dummy driver function to actually get it execute.
- int main()
- {
- fizzbizz();
- }
- // Fizzbizz:
- // print from 1 to 100, substituting in "FizzBuzz", "Fizz" and "Buzz" when the number in
- // question is divisible by 3 and 5, 3 and 5 respectively.
- //
- void fizzbizz()
- {
- // @TODO optional "\N:
- int i;
- for (i=1; i<=100; i++)
- {
- if ((i%3==0) && (i%5==0))
- printf("FizzBuzz");
- else if (i%3==0) //3 divides i. 3 is a factor of i
- printf("Fizz");
- else if (i%5==0)
- printf("Buzz");
- else
- printf("%i",i);
- }
- }
|